英文:
HTML " not converting to ' in Django
问题
以下是翻译好的部分:
我正在创建一个Django应用程序,并尝试在按钮点击时对用户进行身份验证,然后根据其身份验证重定向用户。我有一个按钮用于登录用户,但我想根据他们的身份验证重定向用户。
代码如下:
<button type="submit" class="btn btn-primary" value="Login" onclick="location.href='{% url "auth" %}'">Login</button>
运行代码时,我收到以下错误:
TemplateSyntaxError
无法解析余下的部分:'"auth"' from '"auth"'
这是因为'"'没有按预期工作吗?
有人能否请解释一下这个问题?
英文:
I am creating a django application and was trying to authenticate users on a button click and redirect the users accordingly. I have a button that logs in the user, but I want to redirect the user based on their authentication.
The code is as follows:
<button type="submit" class="btn btn-primary" value="Login" onclick = "location.href='{% url &quot;auth&quot; %}'">Login</button>
While running the code I get the error:
TemplateSyntaxError
Could not parse the remainder: '&quot;auth&quot;' from '&quot;auth&quot;'
Is this because """; is not working as intended?
Could someone please shed some light on this?
答案1
得分: 2
移除&quot;
并将auth
用作字符串文字:
<pre><code><button type="submit" class="btn btn-primary" value="Login" onclick="location.href='{% url <b>'auth'</b> %}'">Login</button></code></pre>
模板标签和模板过滤器由服务器端的*渲染引擎*解释,而不是由JavaScript解释,因此这发生在HTML被“解释”之前。
英文:
Remove the &quot;
and use auth
as string literal:
<pre><code><button type="submit" class="btn btn-primary" value="Login" onclick="location.href='{% url <b>'auth'</b> %}'">Login</button></code></pre>
the template tags and template filters are interpreted by the render engine at the server side, not by JavaScript, so this is before the HTML is "interpreted".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论