2014-10-30 138 views
0

嗨,Python和Django社區。我正在運行某種Youtube的教程。我有錯誤,我無法弄清楚。通過django教程運行的錯誤

這是我的項目結構:

[email protected]:/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 
) 

這是我的... /條/ 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

你可以發佈整篇'article/urls.py'而不只是那個片段嗎? – 2014-10-30 18:11:24

+2

遠射,但是你的urls.py中有''''關閉嗎? – Harpal 2014-10-30 18:12:46

回答

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) 

希望幫助!

+0

是的!這有幫助。感謝名單! :) – 2014-10-31 08:43:29

相關問題