我刚刚开始使用django并正在配置网址。我可以映射不同的网址,如/ posts,/ posts / create等。不知怎的,我无法配置根网址,我不知道我在做什么错。这是我的配置:
urls.py
url(r'^$',homeViews.posts),
# url(r'^blog/', include('blog.urls')),
url(r'^posts/',homeViews.posts),
url(r'^createPost/',homeViews.createPost),
以下是查看代码
def posts(request):
t = get_template('index.html')
postList = Post.objects()
html = t.render(Context({'posts':postList}))
return HttpResponse(html)
奇怪的是,当我在设置中设置DEBUG = True时,root url' ^ $'有效但不是DEBUG = False(400 Bad Request)。不确定有什么问题。 请帮帮我。
编辑:
这是完整的urls.py
from django.conf.urls import url
from rrdquest import views as homeViews
from manage.user import views as userViews
urlpatterns = [
# Examples:
url(r'',homeViews.posts),
# url(r'^blog/', include('blog.urls')),
url(r'^posts/',homeViews.posts),
url(r'^createPost/',homeViews.createPost),
url(r'^createUser/',userViews.createUser),
url(r'^post/(?P<title>[a-z,A-Z]+)/$',homeViews.post),
]
干杯!
答案 0 :(得分:2)
ALLOWED_HOSTS
是设置的必需部分,
因此,应在ALLOWED_HOSTS
settings.py
ALLOWED_HOSTS = ['*']
或者像这样
ALLOWED_HOSTS = ['localhost', '127.0.0.1']