本文介绍了Django 无效语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很聪明.我正在尝试设置 Django 管理员,但我遇到了困难.我已经按照 Django 的书进行了多次检查,但得到了无效的语法(urls.py,第 23 行).
I am at my wits. I am trying to set up Django admin but I am having a hard time. I have followed the Django book and checked several times but get an invalid syntax (urls.py, line 23).
from django.conf.urls.defaults import *
from mysite.views import hello, current_datetime, hours_ahead
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^hello/$', hello),
(r'^time/$', current_datetime),
(r'^time/plus/(\d{1,2})/$', hours_ahead),
(r'^admin/', include(admin.site.urls),
)
任何见解将不胜感激 - 谢谢!
Any insight would be appreciated - thanks!
推荐答案
您缺少第 22 行的右括号:
You are missing a closing parens on line 22:
(r'^admin/', include(admin.site.urls)),
当您在 Python 中遇到 SyntaxError
时,请检查您的括号是否在其前面的行中保持平衡.
When you get a SyntaxError
in Python, check that your parenthesis are balanced on the lines preceding it.
这篇关于Django 无效语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!