简体   繁体   English

如何使用卡上的按钮更改会话值?

[英]How do I use button on card to change a session value?

I am making a menu that goes through a few different steps.我正在制作一个经过几个不同步骤的菜单。 Select the grade, then select the textbook, then select the lesson.选择年级,然后选择教科书,然后选择课程。 I want to display the textbooks as cards with buttons that will bring the user to a view of all the lessons associated with that textbook.我想将教科书显示为带有按钮的卡片,这些按钮将使用户看到与该教科书相关的所有课程。 I've used session to go from the grade to the textbook, but I'm not sure how to go from the textbook to the lessons.我已经使用 session 从成绩到教科书,但我不确定如何从教科书到课程。 I think the way of getting there is to have the button change the session value to that textbook, and bring me to the view that will filter the lessons by that textbook, but I'm not sure how to do that.我认为到达那里的方法是让按钮将会话值更改为该教科书,并将我带到将按该教科书过滤课程的视图,但我不确定如何做到这一点。 Any suggestions would be welcome!欢迎大家提出意见!

Django just isn't capable of rendering a form with choices as images. Django 只是无法渲染带有选项作为图像的表单。 This can only be achieved with a some Java Script or other front end tools.这只能通过一些 Java Script 或其他前端工具来实现。

如何使用按钮显示<div>在 django 模板中?</div><div id="text_translate"><p> results.html</p><pre> {%if searched_user %} &lt;a href= "{{ searched_user }}"&gt;{{searched_user}}&lt;/a&gt; &lt;button id=likedsongsbutton&gt;View liked songs&lt;/button&gt; &lt;div&gt; {% for each_searched_user in searched_user %} &lt;br id="likedsongs"/&gt;{% for liked_songs in each_searched_user.liked_songs.all %}{{liked_songs}} &lt;br/&gt; {% endfor %} {% endfor %} {% endif %} {% endblock %} &lt;/div&gt; &lt;script&gt; document.querySelector("#likedsongsbutton").addEventListener(onclick, ) &lt;/script&gt;</pre><p> views.py</p><pre> def results(request): if request.method == "GET": search_query = request.GET.get("username") searched_user = UserProfile.objects.filter( user__username__contains=search_query ) return render( request, "results.html", { "searched_user":searched_user })</pre><p> 我的问题是如何使&lt;div&gt;仅在单击按钮时显示? 我不知道在EventListener中传递什么function</p></div> - how do I use a button to display <div> in django template?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 HTML 中单击按钮时更改 django 数据库中的值? - How do I change a value in django database on button click in HTML? 如何在 python django 中使用会话变量作为表单字段的默认值? - How do I use session variable as a default value for form field in python django? 我需要更改字段的值并在单击按钮时重定向到URL。 我应该怎么做? - I need to change the value of a field and redirect to a url on button click. How am I supposed to do it? 如何更改 Django Admin 中“添加 [型号名称]”按钮的文本/值? - How do I change the text/value of "Add [Model-Name]" button in Django Admin? 我如何使用Django会话来读取/设置cookie? - How do i use Django session to read/set cookies? 如何更改 Django 中 BooleanField 的值? - How do I change a value of a BooleanField in Django? 如何在Django中更改表单值? - How do I change a form value in Django? 我如何在表单上传按钮 django 上使用 javascript - How do i use use javascript on form upload button django 如何在引导卡中添加图像? - How do I add an image in a bootstrap card? 如何使用按钮显示<div>在 django 模板中?</div><div id="text_translate"><p> results.html</p><pre> {%if searched_user %} &lt;a href= "{{ searched_user }}"&gt;{{searched_user}}&lt;/a&gt; &lt;button id=likedsongsbutton&gt;View liked songs&lt;/button&gt; &lt;div&gt; {% for each_searched_user in searched_user %} &lt;br id="likedsongs"/&gt;{% for liked_songs in each_searched_user.liked_songs.all %}{{liked_songs}} &lt;br/&gt; {% endfor %} {% endfor %} {% endif %} {% endblock %} &lt;/div&gt; &lt;script&gt; document.querySelector("#likedsongsbutton").addEventListener(onclick, ) &lt;/script&gt;</pre><p> views.py</p><pre> def results(request): if request.method == "GET": search_query = request.GET.get("username") searched_user = UserProfile.objects.filter( user__username__contains=search_query ) return render( request, "results.html", { "searched_user":searched_user })</pre><p> 我的问题是如何使&lt;div&gt;仅在单击按钮时显示? 我不知道在EventListener中传递什么function</p></div> - how do I use a button to display <div> in django template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM