我尝试修改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'
我必须更改以修复错误
答案 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-wiki的login_url
代码的来源以获取示例。