我的django应用程序的网址格式为
url(r'^$', include('app.urls')),
一旦我运行服务器并点击网址就会显示错误
语法无效
完整的追溯如下:
`环境:
请求方法:GET
Django版本:1.6
Python版本:2.7.3
已安装的应用程序:
( 'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.messages',
'django.contrib.staticfiles',
'应用')
已安装的中间件:
( 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
回溯:
get_response中的文件“/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py”
- resolver_match = resolver.resolve(request.path_info)
醇>解析文件“/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py”
- for self.url_patterns中的模式:
醇> url_patterns中的文件“/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py”
- patterns = getattr(self.urlconf_module,“urlpatterns”,self.urlconf_module)
醇>文件“/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py”in urlconf_module
- self._urlconf_module = import_module(self.urlconf_name)
醇>import_module中的文件“/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py”
- 导入(名称)
醇>中的文件“/home/pat./urls.py”
- url(r'^ $',include('。urls')),
醇>文件“/usr/local/lib/python2.7/dist-packages/django/conf/urls/init.py”in include
- urlconf_module = import_module(urlconf_module)
醇>import_module中的文件“/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py”
- 导入(名称)
醇>异常类型:/
处的SyntaxError异常值:语法无效(urls.py,第6行)
完整的网址就像这样
from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^', include('mmm.urls')), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), )
这真的是一个语法问题吗? `
答案 0 :(得分:1)
此行不正确。
url(r'^$', include('app.urls')),
插入符^
匹配字符串的开头,而美元$
与字符串的末尾匹配,因此^$
仅匹配索引URL /
。你应该把它改成:
url(r'^', include('app.urls')),
除此之外,如果您不发布整个urls.py,则无法提供帮助。尽量不要更改代码或错误消息。例如,当您将其更改为“app.urls'”时,您可能会在代码中隐藏错误。