嗨,Python和Django社区。 em>我正在运行Youtube的某种教程。我有错误,我无法弄清楚。
这是我的项目结构:
root@ubuntu:/home/lol/django-developer/env16/mysite# tree
.
├── article
│ ├── admin.py
│ ├── admin.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── db-nik-yobana.sqlite3
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
├── polls
│ ├── admin.py
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── tests.py
│ └── views.py
└── templates
└── myview.html
这是... / mysite / urls.py文件:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^basicview/', include('article.urls')), # comment out = no errors
)
这是我的... / article / urls.py文件:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^/1', 'article.views.basic_one'),
url(r'^/2', 'article.views.template_two'),
url(r'^/3', 'article.views.template_three_simple'),
这是我的settings.py文件的一部分:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'article',
当我评论出“url(r'^ basicview /',include('article.urls')),”行时,我没有运行开发Web服务器的错误。 Django服务器显示“它工作了!恭喜你第一个支持Django的页面。“没有评论我在网页上收到错误:
SyntaxError at /
invalid syntax (urls.py, line 7)
Request Method: GET
Request URL: http://192.168.211.128/
Django Version: 1.6
Exception Type: SyntaxError
Exception Value:
invalid syntax (urls.py, line 7)
Exception Location: /home/lol/django-developer/env16/local/lib/python2.7/site- packages/django/utils/importlib.py in import_module, line 40
Python Executable: /home/lol/django-developer/env16/bin/python
Python Version: 2.7.6
Python Path:
['/home/lol/django-developer/env16/mysite',
'/home/lol/django-developer/env16/lib/python2.7',
'/home/lol/django-developer/env16/lib/python2.7/plat-i386-linux-gnu',
'/home/lol/django-developer/env16/lib/python2.7/lib-tk',
'/home/lol/django-developer/env16/lib/python2.7/lib-old',
'/home/lol/django-developer/env16/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-i386-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/lol/django-developer/env16/local/lib/python2.7/site-packages',
'/home/lol/django-developer/env16/lib/python2.7/site-packages']
Server time: Чтв, 30 Окт 2014 13:22:38 +0400
▼ Local vars
Variable Value
urlconf_module
'article.urls'
namespace
None
app_name
None
arg
'article.urls'
我无法得到它。出了什么问题?我明白了,它不喜欢article.urls变量,但我该如何修复呢?
答案 0 :(得分:3)
你在文章/ urls.py文件中遗漏了一个“)”。
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^/1', 'article.views.basic_one'),
url(r'^/2', 'article.views.template_two'),
url(r'^/3', 'article.views.template_three_simple'),
) # <----- you're missing this line?
错误告诉urls.py文件出现问题(在文章应用中):
Exception Type: SyntaxError
Exception Value:
invalid syntax (urls.py, line 7)
希望有所帮助!