django-templates

Django template tags: set .active on the first element of a forloop that satisfies a condition [duplicate]

有些话、适合烂在心里 提交于 2019-12-24 18:43:28
问题 This question already has answers here : ForLoop Iterations as List Index in Django Template (3 answers) Closed 5 years ago . I have the following problem: A user is taking a course on my website. A course consists of several chapters and each chapter consists of several steps. If the user is logged in and completes a step, the backend saves the progress. When the user comes back to the site, I want him to continue where he left off. To do this I have to add the css class "active" to the

django forms - how to update user data from previous comment when user posts a new comment

亡梦爱人 提交于 2019-12-24 18:23:26
问题 I feel like I'm really close, but not quite there yet. Please bear with me as I am very much so in the beginner stages of learning django. I have a feature where users can comment on each blog post. I want to display the total number of comments each user has next to his name. If that user has left 4 comments on 4 different posts, I want it to show "4 total comments" next to his name on each one of his individual comments throughout my website. I have made a model method that I put in my view

Not able to find static file path page redirect to another page

偶尔善良 提交于 2019-12-24 16:31:06
问题 When first time index page load it give static file path: [04/May/2015 09:16:22] "GET / HTTP/1.1" 200 3536 [04/May/2015 09:16:22] "GET /static/css/bootstrap.min.css HTTP/1.1" 304 0 [04/May/2015 09:16:22] "GET /static/js/jquery.js HTTP/1.1" 304 0 [04/May/2015 09:16:22] "GET /static/js/bootstrap.min.js HTTP/1.1" 304 0 [04/May/2015 09:16:22] "GET /static/css/simple-sidebar.css HTTP/1.1" 304 After click on hyperlink it redirect to another page static file path change to: [04/May/2015 10:24:11]

Only last label input value being returned in Django

馋奶兔 提交于 2019-12-24 15:51:57
问题 I am pretty new in Django and I guess there is something I am overlooking. I have a form that I am populating dynamically as shown below <form method="post"> {% csrf_token %} {{ profile.days }}//Only prints last radio button value {% for period, value in profile.periods.items %} <h2>{{ period }} Reports</h2> <label> <input name="days" value={{ value }} type="hidden"> <input name="reports_allowed" type="radio" {% if profile.reports_allowed and profile.days == value %} checked {% endif %}> Each

Receiving 404 error when trying to load static urls directly in Django

♀尐吖头ヾ 提交于 2019-12-24 15:25:26
问题 When I visit the url of my static files (http://127.0.0.1:8000/site_media/static/css/site_base.css) I receive a 404 error message. 404 from the log [27/Oct/2012 14:14:54] "GET /site_media/static/js/libs/modernizr-2.5.2.min.js HTTP/1.1" 404 1716 [27/Oct/2012 14:34:20] "GET /site_media/static/css/site_base.css HTTP/1.1" 404 1677 Directory Structure mysite |-- manage.py |-- mysite |-- settings |-- base.py |-- dev.py |-- prod.py |-- site_media |-- static |-- css |-- site_base.css site_base.html

FormWizard: How to proceed from step 1 to Step 2 when having own 2 templates

 ̄綄美尐妖づ 提交于 2019-12-24 14:12:21
问题 I have 2 steps in formwizard. the first step is where the customer filled up their particular and the second step is about building particular. models.py class customer(models.Model): LAST_NAME = models.CharField(max_length = 50) FIRST_NAME = models.CharField(max_length = 50) ADDRESS = models.CharField(max_length = 60, blank =True) def __unicode__(self): return '{0}' % (self) class building(models.Model): CUSTOMER = models.ForeignKey(customer, null = True, blank = True) BUILDING_USE = models

Django Form Showing No Input Fields

僤鯓⒐⒋嵵緔 提交于 2019-12-24 13:45:01
问题 I am getting a valid response back when requesting my form, but I am getting no form fields with the response. It is loading the Submit button only , but no form fields. Goal: get form fields to load and be able to submit form. I have a views.py : def Registration(request): form = NewUserRegistrationForm(request.POST or None) if request.method == 'POST': if form.is_valid(): form.save() return HttpResponseRedirect("/Login/") else: form = NewUserRegistrationForm() return render(request, 'VA

Django - Create table from list of list

一个人想着一个人 提交于 2019-12-24 13:43:06
问题 I am not very good with table in html, so this question might be very simple to answer. I pass the list of list {{ attributes }} to the template and I want to create a table with 2 rows and many columns. TEMPLATE: <div id="table"> <table border=0> {% for attr in attributes %} <td> <th>{{ attr.0 }}</th> {{ attr.1 }} </td> {% endfor %} </table> </div> I want the {{ attr.0 }} to be the header and displayed on a single row and the {{ attr.1 }} displayed on the second row. 回答1: How about <div id=

NoReverseMatch django Class based views

﹥>﹥吖頭↗ 提交于 2019-12-24 13:33:28
问题 I get this error NoReverseMatch at /author/add/4 Reverse for 'author_update' with arguments '()' and keyword arguments '{'pk': 39, 'user_id': >}' not found. 1 pattern(s) tried: ['author/(?P\d+)/(?P\d+)$'] urls.py url(r'^author/add/(?P<user_id>\d+)$', AuthorCreate.as_view(), name='author_add'), url(r'^author/(?P<user_id>\d+)/(?P<pk>\d+)$', AuthorUpdate.as_view(), name='author_update'), url(r'^author/(?P<user_id>\d+)/(?P<pk>\d+)/delete/$', AuthorDelete.as_view(), name='author_delete'), url(r'

How to select/unselect/delete multiple django items in a table with the same checkbox?

我的未来我决定 提交于 2019-12-24 12:44:01
问题 I have this table of items with their details, and I have implemented a method to 'select' a few items using a submit button, which submits all checked checkboxes on each item. This is the code for the checkbox: <input name='quiz-pids' id='checkbox-{{ quiz.id }}' type="checkbox" value="{{ quiz.id }}" required> As you can see, I have passed the quiz.id in the checkbox value. This is my submit button I am using: <input type="submit" class="btn btn-primary select-btn myitems-select-btn" value=