我需要从客户端的URL获取查询字符串值,该URL是从Django模板传递的。我在下面解释我的代码。你知道吗
base.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
{% load static %}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<header>
<h1>Nuclear Reactor</h1>
{% if count > 0 %}
<b>Hi, {{ user.username }}</b>
<a href="{% url 'home' %}?file=//cdnjs.cloudflare.com/ajax/libs/velocity/1.5.0/velocity.min.js">Home</a>
<a href="{% url 'view_reactor' %}?file=//cdnjs.cloudflare.com/ajax/libs/velocity/1.5.0/velocity.min.js">View Reactor status</a>
<a href="{% url 'logout' %}">logout</a>
{% else %}
<a href="{% url 'login' %}">login</a> / <a href="{% url 'signup' %}">signup</a>
{% endif %}
<hr>
</header>
<main>
{% block content %}
{% endblock %}
</main>
</body>
</html>
这里我传递一些查询字符串值,以便home.html
加载。你知道吗
home.html:
{% extends 'base.html' %}
{% block content %}
<center><h1>Welcome</h1>
<p>This App allow to control the life cycle of the Nuclear Reactor and Retrive the status report </p>
<p><a href="{% url 'status' %}">Status report</a><a href="{% url 'control' %}">Control panel</a></p>
</center>
<script type="text/javascript">
window.onload=function(){
}
</script>
{% endblock %}
当主页呈现时,我需要使用JavaScript获取查询字符串。你知道吗
如果您想在客户端执行此操作,我认为您可以使用javascript location object:
否则,您可以从服务器端(视图中)的请求中获取参数,并将对象注入模板。你知道吗
相关问题 更多 >
编程相关推荐