django-templates

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=

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

Passing variables to CSS file in Django

扶醉桌前 提交于 2021-02-09 07:31:57
问题 Is it possible to pass variables in CSS files, like in HTML file. Example: In views.py: def home(request): bgcolor = "#999" ... ... In the CSS file: body { background-color : {{bgcolor}}; } If yes, can you please guide me how to achieve this? I would really appreciate. Thank you! Edit: Ok, my bad. What I meant was, how do let users customize their page if they wanted to? I suppose I could have done this without using external stylesheet, but I think CSS is served fastest if it's static and on

VariableDoesNotExist: Failed lookup for key [val2] in u'None'

梦想与她 提交于 2021-02-07 12:32:57
问题 I was getting a VariableDoesNotExist error with the following snippet when obj1.page is None . {{ obj1.val1|default:obj1.page.val2 }} Normally Django templates don't care about attribute accesses on None values. 回答1: Django only cares about attribute lookups on None values inside the default template filter. I got around it using: {% with obj1.page.val2 as val2 %} {{ obj1.val1|default:val2 }} {% endwith %} 来源: https://stackoverflow.com/questions/35787497/variabledoesnotexist-failed-lookup-for

VariableDoesNotExist: Failed lookup for key [val2] in u'None'

故事扮演 提交于 2021-02-07 12:32:09
问题 I was getting a VariableDoesNotExist error with the following snippet when obj1.page is None . {{ obj1.val1|default:obj1.page.val2 }} Normally Django templates don't care about attribute accesses on None values. 回答1: Django only cares about attribute lookups on None values inside the default template filter. I got around it using: {% with obj1.page.val2 as val2 %} {{ obj1.val1|default:val2 }} {% endwith %} 来源: https://stackoverflow.com/questions/35787497/variabledoesnotexist-failed-lookup-for