簡體   English   中英

如何在Django urls.py中設置根URL? 的Django 1.8

[英]How to set root url in django urls.py ? Django 1.8

我現在剛開始使用django,並且正在配置url。 我能夠映射不同的URL,如/ posts,/ posts / create等。以某種方式,我無法配置root url,我不確定自己在做什么錯。 這是我的配置:

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時,根URL'^ $'有效,但DEBUG = False(400錯誤請求)無效。 不知道出什么問題了。 請幫幫我。

編輯:

這是完整的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),
]

干杯!

ALLOWED_HOSTS是設置的必需部分,

因此應在settings.py這樣設置ALLOWED_HOSTS

ALLOWED_HOSTS = ['*']

或像這樣

ALLOWED_HOSTS = ['localhost', '127.0.0.1']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM