' wiki_render'没有收到论据的价值:'请求'

时间:2015-03-21 14:09:06

标签: python django wiki

我尝试修改django-wiki

功能

  @register.inclusion_tag('wiki/includes/render.html', takes_context=True)
  def wiki_render(context, article, preview_content=None):

     if preview_content:
      content = article.render(preview_content=preview_content)
     else:
      content = None

看起来像这样

 @register.inclusion_tag('wiki/includes/render.html', takes_context=True)
 def wiki_render(context, article, request, preview_content=None):

     if preview_content:
      content = article.render(preview_content=preview_content)
     else:
      content = None
     if request.user.is_authenticated():
      lastname = request.user.last_name

但是得到

     'wiki_render' did not receive value(s) for the argument(s): 'request'

我必须更改以修复错误

1 个答案:

答案 0 :(得分:1)

如果您想访问request对象,可以从context获取

@register.inclusion_tag('wiki/includes/render.html', takes_context=True)
def wiki_render(context, article, preview_content=None):
    request = context['request']
    ...

请注意,这需要'django.core.context_processors.request'包含TEMPLATE_CONTEXT_PROCESSORS,但这已经是prerequisite of django-wiki

查看django-wikilogin_url代码的来源以获取示例。