我正在学习Django - 几天前。这是我的问题。
http://mylocalhost.com:8000/home/(堆栈溢出不允许localhost所以使用虚拟完整域 - 而mylocalhost.com) 在urls.py
中设置此设置时有效url(r'^home/','signups.views.home')
但在urls.py
中设置此设置时无效url(r'^$','signups.views.home',name='home')
我收到以下错误。 #在下面的错误中将mylocalhost.com读为localhost。 stackoverflow不允许使用localhost。
找不到页面(404) 请求方法:GET 请求网址:http://mylocalhost.com:8000/home/
^ $ [name =' home'] 当前网址/ home /与这些网址中的任何一个都不匹配。
signups
admin.py
__init__.py
models.py
tests.py
views.py
enter code here
from django.shortcuts import render, render_to_response, RequestContext
def home(request):
return render_to_response("signup.html", locals(),
context_instance=RequestContext(request))
答案 0 :(得分:1)
当然它不起作用。 r'^$'
匹配空字符串。您正在使用相对路径/home
要么将正则表达式网址设为r'^home/$'
,要么只访问localhost:8000/
而不使用尾随/home