django-views

AttributeError on successful redirection in django?

谁说我不能喝 提交于 2021-02-11 06:42:37
问题 Redirection on successful POST request from Host View. def product_page_view(request, prod_slug, color=None, size=None): ... ... prod = Product.objects.filter(slug=prod_slug).first() seller = prod.seller ... .... order_form = Buy_now_form() if request.method == "POST": order_form = Buy_now_form(request.POST) if order_form.is_valid(): # Function for processing POST request and return order order = buy_now_view(request, prod.slug, color, size) # Redirection return redirect(reverse('product

Reverse for 'hobbieswithCSS.html' not found. 'hobbieswithCSS.html' is not a valid view function or pattern name (solved)

馋奶兔 提交于 2021-02-11 04:36:34
问题 I am trying to attach hobbieswithCSS.html file to my website, while using Django. I am a beginner when it comes to Django, so I have naturally came across some problems (in the title) like this. I have this anchor tag on my homepage - <a href="{% url 'basic_app:hobbieswithCSS.html' %}">My Hobbies</a> I have this view in my views.py file - def hobbieswithCSS(request): return render(request,'basic_app/hobbieswithCSS.html') I think, that the main problem will be with the urlpatterns in urls.py

Reverse for 'hobbieswithCSS.html' not found. 'hobbieswithCSS.html' is not a valid view function or pattern name (solved)

别等时光非礼了梦想. 提交于 2021-02-11 04:33:58
问题 I am trying to attach hobbieswithCSS.html file to my website, while using Django. I am a beginner when it comes to Django, so I have naturally came across some problems (in the title) like this. I have this anchor tag on my homepage - <a href="{% url 'basic_app:hobbieswithCSS.html' %}">My Hobbies</a> I have this view in my views.py file - def hobbieswithCSS(request): return render(request,'basic_app/hobbieswithCSS.html') I think, that the main problem will be with the urlpatterns in urls.py

Reverse for 'hobbieswithCSS.html' not found. 'hobbieswithCSS.html' is not a valid view function or pattern name (solved)

穿精又带淫゛_ 提交于 2021-02-11 04:33:45
问题 I am trying to attach hobbieswithCSS.html file to my website, while using Django. I am a beginner when it comes to Django, so I have naturally came across some problems (in the title) like this. I have this anchor tag on my homepage - <a href="{% url 'basic_app:hobbieswithCSS.html' %}">My Hobbies</a> I have this view in my views.py file - def hobbieswithCSS(request): return render(request,'basic_app/hobbieswithCSS.html') I think, that the main problem will be with the urlpatterns in urls.py

How to filter a Generic ListView?

久未见 提交于 2021-02-10 16:48:54
问题 I am using a CBV ListView , The problem is, the view returns a list of ALL notes on the system. What I would really prefer is for the list to only return the 'notes' that are associated with a particular CandProfile (model) The notes model is : class CandidateNote(models.Model): candidate = models.ForeignKey(CandProfile, on_delete=models.CASCADE, related_name='candidatenotes_cand') note_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL, related_name=

How to filter a Generic ListView?

馋奶兔 提交于 2021-02-10 16:48:07
问题 I am using a CBV ListView , The problem is, the view returns a list of ALL notes on the system. What I would really prefer is for the list to only return the 'notes' that are associated with a particular CandProfile (model) The notes model is : class CandidateNote(models.Model): candidate = models.ForeignKey(CandProfile, on_delete=models.CASCADE, related_name='candidatenotes_cand') note_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL, related_name=

How to handle data from two forms in one view?

ε祈祈猫儿з 提交于 2021-02-10 15:46:26
问题 So I have two forms.ModelForm for my two models First: class TranslatorChoice(forms.ModelForm): def __init__(self, *args, **kwargs): self.user_id = kwargs.pop('user_id',None) super(TranslatorChoice, self).__init__(*args, **kwargs) self.fields['owner'].queryset = Translator.objects.all().filter(owner_id = self.user_id) owner = forms.ModelChoiceField(queryset = None) class Meta: model = Translator fields = ('owner',) Second: class ProfileChoice(forms.ModelForm): def __init__(self, *args, *

Django: Display File Name for Uploaded File

爷,独闯天下 提交于 2021-02-10 14:26:49
问题 In my model, I have a defined a FileField which my template displays it as a link. My problem is that the linked file displays the url as the name. What shows on html page is: Uploaded File: ./picture.jpg I've looked on the DjangoDocs regarding file names and a previous S.O. question, but just can't figure it out. How can I: Have it display a different name, not a url. Allow the admin who uploaded the file to give it a name, which would then be viewed on the template. my models.py: class

Django Get ID of the object in save()

雨燕双飞 提交于 2021-02-10 07:10:36
问题 I have some fixed number let say it is num = 1000 Now I have field which need to be sum of the object.id and num. I need this in save() something like below. def save(self, *args, **kwargs): num = 1000 self.special = self.id + num super(MyModel, self).save(*args, **kwargs) But self.id is known after save and field named special is required. How to get self.id? 回答1: First of all? Is the number you're trying to add a fixed number? If so, why do you have to store it in the db at all? You may

Django Get ID of the object in save()

北城余情 提交于 2021-02-10 07:08:02
问题 I have some fixed number let say it is num = 1000 Now I have field which need to be sum of the object.id and num. I need this in save() something like below. def save(self, *args, **kwargs): num = 1000 self.special = self.id + num super(MyModel, self).save(*args, **kwargs) But self.id is known after save and field named special is required. How to get self.id? 回答1: First of all? Is the number you're trying to add a fixed number? If so, why do you have to store it in the db at all? You may