Answer the question
In order to leave comments, you need to log in
How to redirect to a subdomain in django?
Task:
redirect from mysite.com/shop_slug/action to shop_slug.mysite.com/action
Installed django-hosts, registered hosts.py:
from django_hosts import patterns, host
host_patterns = patterns('',
host(r'(?P<shop_slug>\w+)', 'shop.urls', name='shop_sub'),
host(r'www', 'main.urls', name='home'),
)
from django.conf.urls import url
from shop import views
urlpatterns = [
url('^(?P<slug>\w+)/$', views.ProductListView.as_view(), name='product_list'),
url('^$', views.CreateShopView.as_view(), name='create_shop'),
url(r'^(?P<slug>\w+)/product/(?P<productId>\d+)/$', views.ProductDetailView.as_view(),
name="product_detail"),
url(r'^(?P<slug>\w+)/category/(?P<category_id>\d+)/$', views.CategoryView.as_view(), name='view_category'),
]
ROOT_URLCONF = 'main.urls'
DEFAULT_HOST = 'home'
ROOT_HOSTCONF = 'hosts'
Answer the question
In order to leave comments, you need to log in
serverfault.com/questions/458958/how-to-set-multip...
# echo "127.0.0.1 shop_slug.localhost" >> /etc/hosts
First, you first write what you want from mysite.com/shop_slug/ to make shop_slug.mysite.com , and as a result, working with localhost, break into shop_slug.com . Those. you work with a domain not of the 3rd level, but of the 2nd. But, in general, this is not important - on the localhost, you can intercept all requests, you just need to tell the djanga what exactly it should listen to. There, in the comments, they suggested raising their dns, and this is true - in a different way, the wildcard will not be able to specify the local domain. And I think that such a config will not work with a dev server anyway.
Second, are you sure this is a good idea? It seems to me that nginx should deal with such redirection, not dzhanga.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question