gpt4 book ai didi

Django:urls.py 中的语法错误

转载 作者:行者123 更新时间:2023-12-01 09:34:00 25 4
gpt4 key购买 nike

from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^events/', include('events.urls')),
)

这是我的 events.urls:
from django.conf.urls.defaults import *
from events import views


urlpatterns = patterns('',
url(r'^tonight/$', views.tonight, name='ev_tonight'),
)

运行服务器后出现以下错误:
Exception Type:     SyntaxErrorException Value:    

invalid syntax (urls.py, line 8)

Am I missing something here?

Edit: Attaching the traceball

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'events')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
89. response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
67. if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in is_valid_path
531. resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
420. return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
298. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
323. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/bhavish/startthedark/startthedark/urls.py" in <module>
8. (r'^events/', include('events.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
24. urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)

Exception Type: SyntaxError at /admin
Exception Value: invalid syntax (urls.py, line 8

)

最佳答案

引发的错误在 events/urls.py 中——仔细检查该文件。在它的末尾可能有一些您看不到的额外空白。 (语法错误应该在第 8 行,但我在您粘贴的内容中没有看到 8 行)

您还可以尝试直接从 python shell 导入该文件,以查看它是否完全解析。

关于Django:urls.py 中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11669234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com