[英]How can I get/pass the string from HTML file to Views file in Django?
I've some strings/text in an HTML file. 我在HTML文件中有一些字符串/文本。 I want a new page when I click on them and individual string to give different view.
当我单击它们和单个字符串以给出不同的视图时,我想要一个新页面。 How can I get the text/string from HTML to a Django view so that I can use them?
如何从HTML将文本/字符串获取到Django视图,以便可以使用它们?
first_key is zip file so I'm lopping through two list items ad getting those list items as strings/text to print on one of my page. first_key是zip文件,因此我浏览了两个列表项广告,将这些列表项作为字符串/文本来打印在我的一个页面上。 Upon clicking them I want a new page which I'm getting but unable to get the string/text/item value on which I clicked.
单击它们后,我想要一个新页面,但无法获得我单击的字符串/文本/项目值。 I want the value '{{i}}' in my views.
我希望视图中的值为“ {{i}}”。 I've tried request.POST.get['mytext'] but all I'm getting is NONE.
我已经尝试过request.POST.get ['mytext'],但是我得到的只是NONE。 I want '{{i}}' stored in a variable in my views.py file.
我希望将“ {{i}}”存储在views.py文件的变量中。
{% for i,j in first_key %}
<tr>
<td><a name="my_text" href = "{% url 'search_app:page'%}" >{{i}}</a></td>
<td>{{ j }}</td>
</tr>
{% endfor %}
根据您的代码从i = request.POST.get['my_text']
获取i的值
<td><a name="my_text" href = "{% url 'search_app:page'%}" >{{i}}</a></td>
Well... I found the answer and I'm posting it for others. 好吧...我找到了答案,并且正在将其发布给其他人。 @dirkgroten helped me in finding it out.
@dirkgroten帮助我找到了它。
First of all I passed the value from href in anchor tag itself through URL something like "{% url 'my_app:page' key=i %}"
首先,我通过URL传递了锚标签本身中href中的值,例如
"{% url 'my_app:page' key=i %}"
then in my urls.py file I changed the path from page_view/
to page_view/?P<key>[\\w+]+
然后在我的urls.py文件中,将路径从
page_view/
更改为page_view/?P<key>[\\w+]+
and lastly in my views.py file I pass the key-value as an argument in the function something like def page(request, key):
and then I was able to use the value of key in one of my views. 最后,在我的views.py文件中,我将键值作为参数传递给函数,例如
def page(request, key):
然后我可以在其中一个视图中使用key的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.