Django EOL在urls.py中

时间:2012-07-11 19:20:20

标签: python django django-urls eol

当我启动我的django服务器并键入一些url django总是给我一个EOL错误:

SyntaxError at /accounting/payments/
    EOL while scanning string literal (urls.py, line 22)
    Request Method: GET
    Request URL:    http://localhost:8000/accounting/payments/
    Django Version: 1.4
    Exception Type: SyntaxError
    Exception Value:    
    EOL while scanning string literal (urls.py, line 22)
    Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py in import_module, line 35
    Python Executable:  /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
    Python Version: 2.7.3
    Python Path:    
    ['/Users/Tone/Documents/Proyectos/macrogest/MacroTelecom',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.27-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/South-0.7.5-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_debug_toolbar-0.8.5-py2.7.egg',
     '/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg',
     '/Library/Python/2.7/site-packages/ipython-0.13-py2.7.egg',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL',
     '/Users/Tone/Documents/django/django',
     '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info',
     '/Library/Python/2.7/site-packages',
     '/Users/Tone/Documents/Django']

这是我的 urls.py 代码:

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
#from django.contrib import admin
#admin.autodiscover()

urlpatterns = patterns('',

    # Site control
    url(r'^$', 'macrotelecom.base.views.home', name='home'),
    url(r'^company/', include('macrotelecom.company.urls')),
    url(r'^people/', include('macrotelecom.people.urls')),
    url(r'^lines/', include('macrotelecom.lines.urls')),
    url(r'^accounting/', include('macrotelecom.accounting.urls')),
    url(r'^sales/', include('macrotelecom.sales.urls')),
    url(r'^shop/', include('macrotelecom.shop.urls')),
    url(r'^news/', include('macrotelecom.news.urls')),
    url(r'^map/', 'macrotelecom.base.views.webmap', name='map'),
    url(r'^error/$', 'macrotelecom.base.views.error', name='error'),

    # Internal
    url(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', {'url': '/static/img/favicon.ico'}),
    url(r'^i18n/', include('django.conf.urls.i18n')),
    #url(r'^admin/', include(admin.site.urls)),
    url(r'^rosetta/', include('rosetta.urls')),

    # User control
    (r'^not_authorized/$', 'base.views.not_authorized'),
    (r'^login/$', 'django.contrib.auth.views.login'),
    (r'^logout/$', 'django.contrib.auth.views.logout'),
    (r'^password_change/$','django.contrib.auth.views.password_change'),
    (r'^password_change/done/$','django.contrib.auth.views.password_change_done'),
    (r'^password_reset/$','django.contrib.auth.views.password_reset'),
    (r'^password_reset/done/$','django.contrib.auth.views.password_reset_done'),
    (r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$','django.contrib.auth.views.password_reset_confirm'),
    (r'^reset/done/$','django.contrib.auth.views.password_reset_complete'),

)

第22行与favicon网址对应,我认为可能是scape字符或者其他类似的东西(我发了#评论)但是没有用,总是说EOL错误,它会是什么?

1 个答案:

答案 0 :(得分:3)

该文件(至少是您发布的部分)没有任何语法错误。有时错误可能来自不同的文件。

只需在python myapp/views.py左右运行解释器,即可检查您最近编辑过的文件。如果你得到NameError或ImportError,或者它运行正常,那么myapp/views.py中没有语法错误,所以请尝试另一个文件。