/admin/ 处的 TemplateSyntaxError 渲染时捕获 SyntaxError:语法无效
我有一个名为 blogspot 的应用程序,每当我将与该应用程序相关的 url 添加到项目 urls.py 文件中时,我都会收到上述错误。 blogspot 应用程序的 urls.py 文件的代码
from django.conf.urls.defaults import *
from blogspot.models import UserBlog
from tagging.views import tagged_object_list
from hitcount.views import update_hit_count_ajax
info_dict =
{
'queryset': UserBlog.objects.filter(status=1),
'date_field': 'pub_date',
}
urlpatterns = patterns('',
url(r'^new/$', 'blogspot.views.blog_form' , name = 'blog_new'),
url(r'^edit/(?P<blog_id>\d+)/$', 'blogspot.views.blog_form', name = 'blog_edit'),
url(r'^delete/(?P<blog_id>\d+)/$', 'blogspot.views.blog_delete', name = 'blog_delete'),
url(r'^all/$', 'blogspot.views.all_blogs', name = 'blog_all'),
url(r'^view/(?P<blog_id>\d+)/$', 'blogspot.views.blog_view', name = 'blog_view'),
url(r'^ajax/hit/$',update_hit_count_ajax,name='hitcount_update_ajax'),
)
urlpatterns += patterns('django.views.generic.date_based',
url(r'(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$', 'object_detail', dict(info_dict, slug_field='slug',template_name='blogspot/detail.html')),
url(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$', 'object_detail', dict(info_dict, template_name='blogspot/list.html')),
url(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/$','archive_day',dict(info_dict,template_name='blogspot/list.html')),
url(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/$','archive_month', dict(info_dict, template_name='blogspot/list.html')),
url(r'^(?P<year>d{4})/$','archive_year', dict(info_dict, template_name='blogspot/list.html')),
url(r'^$','archive_index', dict(info_dict, template_name='blogspot/list.html')),
)
我不明白,添加此 url 文件如何也会弄乱管理 url。
更新
当我从 urls.py 文件中删除所有行时,一切都运行正常。然而,即使我添加一行,整个事情就会变得异常。我不明白即使它不起作用也没有语法错误。
更多更新
我认为这个问题可能是因为应用程序的views.py文件,因为每个其他py文件都有它的.pyc文件,但没有views.py文件。 urls.py 文件中语法上没有错误。
I have an app names blogspot and when ever I add the urls related to this app, into the project urls.py file I get the above given error. The code for the urls.py file for the blogspot app is
from django.conf.urls.defaults import *
from blogspot.models import UserBlog
from tagging.views import tagged_object_list
from hitcount.views import update_hit_count_ajax
info_dict =
{
'queryset': UserBlog.objects.filter(status=1),
'date_field': 'pub_date',
}
urlpatterns = patterns('',
url(r'^new/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
, 'blogspot.views.blog_form' , name = 'blog_new'),
url(r'^edit/(?P<blog_id>\d+)/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
, 'blogspot.views.blog_form', name = 'blog_edit'),
url(r'^delete/(?P<blog_id>\d+)/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
, 'blogspot.views.blog_delete', name = 'blog_delete'),
url(r'^all/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
, 'blogspot.views.all_blogs', name = 'blog_all'),
url(r'^view/(?P<blog_id>\d+)/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
, 'blogspot.views.blog_view', name = 'blog_view'),
url(r'^ajax/hit/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
,update_hit_count_ajax,name='hitcount_update_ajax'),
)
urlpatterns += patterns('django.views.generic.date_based',
url(r'(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
, 'object_detail', dict(info_dict, slug_field='slug',template_name='blogspot/detail.html')),
url(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
, 'object_detail', dict(info_dict, template_name='blogspot/list.html')),
url(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
,'archive_day',dict(info_dict,template_name='blogspot/list.html')),
url(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
,'archive_month', dict(info_dict, template_name='blogspot/list.html')),
url(r'^(?P<year>d{4})/
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
,'archive_year', dict(info_dict, template_name='blogspot/list.html')),
url(r'^
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
,'archive_index', dict(info_dict, template_name='blogspot/list.html')),
)
I don't understand, how adding this url file is messing up with the admin urls as well.
Update
When I remove all the lines from urls.py file, then everything is running fine. However even if I add one line the whole thing goes rogue. I don't understand there is no syntax error even then it is not working.
More Update
I think this problem maybe because of the views.py file of the app because, each other py file has it's .pyc file but not the views.py file. Syntactically there is no error in the urls.py file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于导入方式的原因,URL 文件中的错误可能会给出该错误消息。
在您发布的示例中,您在末尾缺少右大括号。如果这只是复制和粘贴造成的,请尝试注释掉每一行,然后依次重新引入它们以找出导致问题的行。
An error in your URL file can give that error message, due to the way things are imported.
In the example you posted, you're missing a closing brace at the end. If that's just from copying and pasting, try commenting each line out, then re-introducing them in turn to find which one is causing the problem.
刚刚遇到这个问题。发现这是我的视图文件中的错误。
Just had this problem. Discovered it was an error in my views file.