mardi 5 mai 2015

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

I have just started with django now and was configuring urls. I am able to map different urls like /posts, /posts/create etc. Somehow I am not able to configure root url, I am not sure what wrong I am doing. Here is my configuration :

urls.py

url(r'^$',homeViews.posts),
# url(r'^blog/', include('blog.urls')),
url(r'^posts/',homeViews.posts),
url(r'^createPost/',homeViews.createPost),

Here is the View Code

def posts(request):
  t = get_template('index.html')
  postList = Post.objects()
  html = t.render(Context({'posts':postList}))
  return HttpResponse(html)

Strange thing is, when I set DEBUG=True in settings, root url '^$' works but not with DEBUG=False (400 Bad Request). Not sure what is wrong. Please help me out .

Edit :

Here is the complete 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),
]

Cheers!

Aucun commentaire:

Enregistrer un commentaire