【发布时间】:2017-07-14 02:57:18
【问题描述】:
我开始研究 Django 1.10,但它使用了 1.6 上的示例。这就是我在新版本中遇到语法问题的原因。
这是我的功能:
def article(request, article_id=1):
comment_form = CommentForm
@csrf_protect
args = {}
args['article'] = Article.objects.get(id=article_id)
args['comments'] = Comments.objects.filter(comments_artile_id=article_id)
args['form'] = comment_form
return render (request, 'articles.html', args)
还有我的追溯:
File "/home/goofy/djangoenv/bin/firstapp/article/views.py", line 30
args = {}
^
SyntaxError: invalid syntax
请告诉我什么是正确的语法或在哪里可以找到答案,因为我在 Django Docs 中找不到任何解释。
【问题讨论】:
-
尝试将
@csrf_protect放在函数上方。 -
你是对的,这是一个错误。谢谢
-
@AlexeyG 欢迎来到 StackOverflow!如果您的问题已解决,请选择一个答案以标记为已接受,并为您认为有帮助的任何内容点赞。这有助于后来的人知道哪些答案最有帮助,同时也奖励那些竭尽全力帮助你的人。