3

当我启动我的 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 url,我认为这可能是 scape 字符或类似的东西(我放了一个 # 用于评论)但没有用,总是说 EOL 错误,它可能是什么?

4

1 回答 1

3

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

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

于 2012-07-11T19:29:20.663 回答