Django urls.py and views.py behaviour -

♀尐吖头ヾ 提交于 2019-12-06 19:32:31

First of all, for the pattern to match

(r'^/$','ulogin.views.index')

Should be

(r'^$','ulogin.views.index')

Also, trying to match the following URL would raise errors

(r'^ucode/(\d+)/$', 'ulogin.views.index'), 

because there is no view method that takes \d+ as a parameter.

The fix i recommend is:

(r'^ucode/(<?P<id>[\d]+)/$', 'ulogin.views.index'),

and then

def index(request, id=None):
    return HttpResponse("Hello, world. You're at the poll index.")

You can read more about named URL groups here

It does not work because the root of a web-server when it comes to django urls is characterized by the empty string, like so -> ^$. So, just change ^/$ to ^$, and it will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!