我尝试修改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'


我必须更改以解决错误

最佳答案

如果要访问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标记的来源。

关于python - 'wiki_render'没有收到参数的值:'request',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29183653/

10-16 00:49