django-templates

Access named URL parameter in Template or Middleware

痴心易碎 提交于 2020-07-29 12:15:17
问题 In my url conf, I have several URL's which have the same named parameter, user_id . Is it possible to access this parameter either in a middleware - so I can generically pass it on to the context_data - or in the template itself? Sample URL conf to illustrate the question: url(r'^b/(?P<user_id>[0-9]+)/edit?$', user.edit.EditUser.as_view(), name='user_edit'), url(r'^b/(?P<user_id>[0-9]+)/delete?$', user.delete.DeleteUser.as_view(), name='user_delete') 回答1: If you need this data in the template

How can I delete the answers (code in body)?

寵の児 提交于 2020-07-23 06:45:18
问题 I am creating a Q&A website for practice, I created the answer and the question model and linked them together, however I can not access the template that I set for the deletion of the answer model, I created a DeleteView to delete the question. Here is the code: views.py : class Politics_post_details(DeleteView): model = PoliticsPost context_object_name = 'politicsposts' pk_url_kwarg = 'qid' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # now you can get

How can I delete the answers (code in body)?

人走茶凉 提交于 2020-07-23 06:43:38
问题 I am creating a Q&A website for practice, I created the answer and the question model and linked them together, however I can not access the template that I set for the deletion of the answer model, I created a DeleteView to delete the question. Here is the code: views.py : class Politics_post_details(DeleteView): model = PoliticsPost context_object_name = 'politicsposts' pk_url_kwarg = 'qid' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # now you can get

Django _set.all filter not working in template

依然范特西╮ 提交于 2020-07-22 22:03:06
问题 I'm trying to filter a list of objects in my database but I can't get it to work on the template using _set.all . The strange thing is it's something I've done in two other places in my project but I cant see why it isnt working this time. view.py: class GolfMonthlyView(generic.ListView): template_name="monthly_view/golf-monthly-view.html" context_object_name='golf_monthly_view' queryset = GolfMonthlyView.objects.all() def get_context_data(self, **kwargs): context = super(GolfMonthlyView,

How do I remove Label text in Django generated form?

最后都变了- 提交于 2020-07-18 04:16:23
问题 I have a form that is displaying well only for the label text that I don't want and I have tried all I could to let it off my form but it won't just go... forms.py : class sign_up_form(forms.ModelForm): class Meta: model = Users fields =['email'] widgets = { 'email': forms.EmailInput(attrs={ 'id': 'email', 'class': 'form-control input-lg emailAddress', 'name': 'email', 'placeholder': 'Enter a valid email'})} I have tried: views.py : from django.shortcuts import render from mysite.forms import

Disable Choice In ModelMultipleChoiceField CheckBoxSelectMultiple Django

倾然丶 夕夏残阳落幕 提交于 2020-07-15 15:17:06
问题 All, I have researched this for a couple of days, and can't quite seem to find what I'm looking for. I am well aware of using the following to disable a field in a Django form: self.fields['author'].disabled = True The above will disable a field entirely. I am trying to display a checkbox with multiple select options, but I want one of the choices to be automatically selected and disabled so the user can not change it as one of the choices they have selected. Here is the code that I've been

form.save() not working my form.save for updating data isnt working

爱⌒轻易说出口 提交于 2020-07-14 12:06:18
问题 form.save() not working my form.save for updating data isnt working when i try to update my post it shows the original unedited post it dosent save the updated version.i donnt know whats causing the error idk if its views or anything in template if anyone could help i will be very grateful please help. here is the code: views.py from django.shortcuts import render from django.shortcuts import HttpResponseRedirect from .models import Post from .forms import PostForm def post_list(request):

form.save() not working my form.save for updating data isnt working

↘锁芯ラ 提交于 2020-07-14 12:03:39
问题 form.save() not working my form.save for updating data isnt working when i try to update my post it shows the original unedited post it dosent save the updated version.i donnt know whats causing the error idk if its views or anything in template if anyone could help i will be very grateful please help. here is the code: views.py from django.shortcuts import render from django.shortcuts import HttpResponseRedirect from .models import Post from .forms import PostForm def post_list(request):

Use of related field name in django template

旧街凉风 提交于 2020-07-11 04:28:31
问题 I have tow models like below: class A(models.Model): a = models.BooleanField(default=False) q = models.BooleanField(default=False) class B(models.Model): c = models.Foreignkey('A', related_name='bb') d = models.BooleanField(default=False) e = models.BooleanField(default=False) Here is my view: class Myview(ListView): model = A template_name = 'admin/layer.html' def get_context_data(self, *args, **kwargs): context = super(ListView, self).get_context_data(*args, **kwargs) context['mylist'] = A

Traverse multiple foreign keys in Django DetailView

ぃ、小莉子 提交于 2020-07-10 08:43:05
问题 I'm working on a project to record all scores shot at a bunch of archery events. They are shot by many people at many events and many different archery rounds. (A "round" in archery is a particular type of competition. For the sake of simplicity let's say there are two: indoor and outdoor.) Here's a basic ER diagram of the relevant part of my database model: ┌───────────┐ ┌───────────┐ ┌────────────────┐ ┌───────────┐ │ │ ╱│ │╲ │ │╲ │ │ │ Person │──────┼──│ Score │──┼────│ EventRound │──┼────