我正在使用 Django 包django-subdomain,但我认为我没有正确配置它。
现在我正在尝试从数据库加载数据,我在终端中收到此错误
主机 localhost:8000 不属于域 example.com,无法识别该请求的子域
我的项目中没有对 example.com 的任何引用。
这是我的子域配置:
ROOT_URLCONF = 'creativeflow.urls'
# A dictionary of urlconf module paths, keyed by their subdomain.
SUBDOMAIN_URLCONFS = {
None: ROOT_URLCONF, # no subdomain, e.g. ``example.com``
'www': ROOT_URLCONF,
'blog': ROOT_URLCONF + '.blogs',
}
SITE_ID = 1
中间件:
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'subdomains.middleware.SubdomainURLRoutingMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
我的网址:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^posts/(?P<year>\d{4})/(?P<months>\d{2}|\w{3})/(?P<day>\d{2})',
BlogListView.as_view(paginate_by=25), name="blog-list-view"),
]
我不确定我需要什么其他配置才能让我使用/开发子域。我需要更改什么才能访问 BlogListView http://localhost:8000/posts/2016/07/09
?或者通过实际的子域更好blog.creativeflow.com/posts/2016/07/09
?我怀疑后者只是对相当于/etc/hosts/
.