我使用的是django框架,我遇到了错误
这是我的settings.py,INSTALLED_APPS
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.staticfiles',
'apps',
)
,这是我的apps /目录。
apps/
__init__.py
qnaBoard/
admin.py
migrations/
tests.py
views.py
urls.py
__init__.py
models.py
urls.py
并且,这是我的urls.py,它与settings.py。
位于同一目录中from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^course/', include('apps.qnaBoard.urls')),
url(r'^admin/', include(admin.site.urls)),
)
我认为我遵循正确的方式,但是,它说它无法找到apps.qnaBoard.urls,并引发语法错误。
这是追溯:
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
98. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
343. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
372. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
366. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/root/campusmate/campusmate/campusmate/urls.py" in <module>
9. url(r'^course/', include('apps.qnaBoard.urls')), #need to apply course router
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
28. urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
Exception Type: SyntaxError at /course/
Exception Value: invalid syntax (urls.py, line 4)
这是apps / qnaBoard / urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from apps.qnaBoard.views import showPost
from apps.qnaBoard.views import showQuestionThread
from apps.qnaBoard.views import writeReply
from apps.qnaBoard.views import writeQuestion
from apps.qnaBoard.views.import writeAnswer
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'campusmate.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
# need to be refactored when course router are attached.
url(r'^([0-9]+)/([1-4])/([A-Za-z0-9]+)/article/list/', showPost.as_view()),
url(r'^([0-9]+)/([1-4])/([A-Za-z0-9]+)/article/([0-9]+)/$', showQuestionThread.as_view()),
url(r'^([0-9]+)/([1-4])/([A-Za-z0-9]+)/article/([0-9]+)/reply', writeReply.as_view()),
url(r'^([0-9]+)/([1-4])/([A-Za-z0-9]+)/article/write/$', writeQuestion.as_view()),
url(r'^([0-9]+)/([1-4])/([A-Za-z0-9]+)/article/write/([0-9]+)/$', writeAnswer.as_view()),
)
答案 0 :(得分:-2)
从网址中删除.
。
问题出现在以下文件中:
文件名: apps / qnaBoard / urls.py
from apps.qnaBoard.views.import writeAnswer
.
就在那里,将其删除。