如何强制django应用程序不提供子域

时间:2010-12-18 11:28:34

标签: django dns subdomain django-urls

我有两个单独的django应用程序,一个用于整个站点,第二个用于网上商店。我的主要应用程序位于http://www.sitedomain.com下。现在我想在http://www.sitedomain.com/shop下运行网上商店。有没有办法强制主项目不要提供这个子域,并使商店应用程序只在子域下运行?


修改

从答案中尝试了解决方案,但仍然与主要应用程序捕获与/ shop的所有链接。它的网址还有多个问题。他们的Mos现在不起作用。

我的网址:

# Django 
urlpatterns = patterns('',
    url('^accounts/login/?$', login, {"template_name" : "admin/login.html"}, name='auth_login'),
    url('^accounts/logout/?$', logout, name='auth_logout'),
    (r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/media/theme/img/s4lfav.ico'}),
    (r'^admin/(.*)', admin.site.root),
    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': ('django.conf') }),
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': os.path.join(DIRNAME, "media"), 'show_indexes': True }),
)

# Login / Logout
urlpatterns += patterns('django.contrib.auth.views',
    url('^login/?$',  "login",  { "template_name" : "login.html" },  name='login'),
    url('^logout/?$', "logout", { "template_name" : "logged_out.html" }, name='logout'),
)

# Contact form
urlpatterns += patterns('contact_form.views',
    url(r'^contact$', "contact_form", { "form_class" : ContactForm }, name='contact_form'),
    url(r'^sent$', direct_to_template, { 'template': 'contact_form/contact_form_sent.html' }, name='contact_form_sent'),
)

# Sitemaps
urlpatterns += patterns("django.contrib.sitemaps.views",
    url(r'^sitemap.xml', 'sitemap', {'sitemaps': {"pages": PageSitemap}})
)

# Robots
urlpatterns += patterns('django.views.generic.simple',
    (r'^robots.txt', 'direct_to_template', {'template': 'robots.txt'}),
)


urlpatterns += patterns("manage.views",
    url(r'^manage$', "site", name="manage_site"),
    url(r'^manage$', "site", name="manage_site"),
)

# SITE
urlpatterns += patterns('views',
    url(r'^search', "search", name="search"),
    #url(r'^/$', "base_view", name="index_view"),
    #url(r'^/(?P<slug>.*)', "index_view", name="index_view"),
    url(r'^(?P<slug>.*)$', "index_view", name="index_view"),
    url(r'^$', "index_view", name="index_view"),
    #url(r'^/', "index_view", name="index_view"),
)

# Manage
urlpatterns += patterns('manage.views',
    url(r'^manage/applications$', "applications", name="applications"),
    url(r'^manage/install-application/(?P<name>\w+)$', "install_application", name="install_application"),
    (...)

1 个答案:

答案 0 :(得分:2)

在url.py中明确列出主应用的所有支持网址,而不是在顶层使用通配符。