Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 以下django代码中有错误吗?_Python_Django - Fatal编程技术网

Python 以下django代码中有错误吗?

Python 以下django代码中有错误吗?,python,django,Python,Django,我使用django消息传递框架来显示一次性消息。一切正常,只是渲染不好。无法解决问题。 Python代码: @receiver(user_signed_up) def on_user_signed_up(sender, request, user, **kwargs): context={'request':request} msg='You have completed the first step of <a href="%s">Getting started w

我使用django消息传递框架来显示一次性消息。一切正常,只是渲染不好。无法解决问题。 Python代码:

@receiver(user_signed_up)
def on_user_signed_up(sender, request, user, **kwargs):
    context={'request':request}
    msg='You have completed the first step of <a href="%s">Getting started with MDN</a>' % wiki_url(context, 'MDN/Getting_started')
    messages.success(request, msg)
@receiver(用户已注册)
用户注册时的def(发件人、请求、用户,**kwargs):
上下文={'request':请求}
msg='您已经完成了'%wiki\u url'的第一步(上下文'MDN/Getting\u started')
messages.success(请求、消息)
jinja2代码:

<div class="one time message">
        {% if messages %}
        <ul>
            <li>{{ _('messages') }}</li>
        </ul>
        {% endif %}
    </div>

{%if消息%}
  • {{{('messages')}
{%endif%}
期望输出:您已经完成了

我的输出:您已经完成了

注意:wiki_url是一个将路径转换为url的实用程序

在django消息框架中,添加额外的标签class='safe'将消息标记为安全的。以“另一个选择是……”开头的答案是对我有用的

它是如何被正确呈现的?通过添加标签,您并没有将消息标记为安全的,如果需要在模板中添加额外的
。。。您只需拨打1个
mark\u safe
call即可完成此操作。。。
   My output: You have completed the first step of <a href"replaced url">Getting started with MDN</a>