django-templates

Display Django values() on Foreign Key in template as object instead of its id

我的梦境 提交于 2020-01-12 14:24:09
问题 I have a queryset in Django that calls Model.objects.values('item') ... where 'item' is a Foreign Key. class Words(models.Model): word = models.CharField() class Frequency(models.Model): word = models.ForeignKey(Words) ... So this returns the item id and displays as an id in the template. How do I show the actual item value in the template instead of the id? 回答1: To refer properties of Foreign Key items, you should use '__' lookup notation in fields. MyModel.objects.values('item__prop1',

initial value in radio button django form

馋奶兔 提交于 2020-01-12 14:17:39
问题 how can I declare initial value of radio button? form.py YESNO = ( ('Yes','Yes'), ('No', 'No'), ) class MyForm(forms.Form): like = forms.ChoiceField(widget=forms.RadioSelect, choices=YESNO) myhtml.html {{form.like}} i try to put: like = forms.ChoiceField(widget=forms.RadioSelect, choices=YESNO, initial={'Yes':'Yes'}) when i run my code, my radio button has not yet selected.. 回答1: i put the initial value direct in my views.py ... def myviews(request): ..... form = MyForm({'like':'Yes'}) ...

initial value in radio button django form

╄→гoц情女王★ 提交于 2020-01-12 14:16:11
问题 how can I declare initial value of radio button? form.py YESNO = ( ('Yes','Yes'), ('No', 'No'), ) class MyForm(forms.Form): like = forms.ChoiceField(widget=forms.RadioSelect, choices=YESNO) myhtml.html {{form.like}} i try to put: like = forms.ChoiceField(widget=forms.RadioSelect, choices=YESNO, initial={'Yes':'Yes'}) when i run my code, my radio button has not yet selected.. 回答1: i put the initial value direct in my views.py ... def myviews(request): ..... form = MyForm({'like':'Yes'}) ...

MultiValueDictKeyError generated in Django after POST request on login page

两盒软妹~` 提交于 2020-01-12 07:37:07
问题 I'm trying to build a login page. I'm running Django 1.6.1. I've largely been following the tutorial at www.fir3net.com/Django/django.html. For convenience I will repost a lot of it here. Error Message: Request Method: GET Request URL: http://127.0.0.1:8000/login/ Database In Use: SQLite3 Django Version: 1.6.1 Python Version: 2.7.4 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages',

Django - Template tags in javascript and css files

萝らか妹 提交于 2020-01-12 07:14:27
问题 Is there any way to add template tags into javascript and css files? I would use it for anything from passing in urls to media url links (image paths, etc) to conditional javascript based on user permissions. I just had a thought that maybe I can serve it up as if it were a template but have the url as my javascript file. Is that the only way to do somethign like this? If so, it probably wouldn't work with my media generator, so I'd probably want a better solution if there was one out there.

Django 2.0 - Not a valid view function or pattern name (Customizing Auth views)

爷,独闯天下 提交于 2020-01-12 07:06:48
问题 I´m working on a course exercise and I'm stuck for a few hours and I'm not sure what is causing the app to break, next, you will find the files involved and perhaps you can find out the solution. Thanks for your help! Project structure This error is being thrown when I log in: Internal Server Error: /account/login/ ... django.urls.exceptions.NoReverseMatch: Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name. [04/Apr/2018 17:12:15] "POST /account/login/

Django 2.0 - Not a valid view function or pattern name (Customizing Auth views)

不羁岁月 提交于 2020-01-12 07:06:27
问题 I´m working on a course exercise and I'm stuck for a few hours and I'm not sure what is causing the app to break, next, you will find the files involved and perhaps you can find out the solution. Thanks for your help! Project structure This error is being thrown when I log in: Internal Server Error: /account/login/ ... django.urls.exceptions.NoReverseMatch: Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name. [04/Apr/2018 17:12:15] "POST /account/login/

Django 2.0 - Not a valid view function or pattern name (Customizing Auth views)

天大地大妈咪最大 提交于 2020-01-12 07:06:25
问题 I´m working on a course exercise and I'm stuck for a few hours and I'm not sure what is causing the app to break, next, you will find the files involved and perhaps you can find out the solution. Thanks for your help! Project structure This error is being thrown when I log in: Internal Server Error: /account/login/ ... django.urls.exceptions.NoReverseMatch: Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name. [04/Apr/2018 17:12:15] "POST /account/login/

Django 2.0 - Not a valid view function or pattern name (Customizing Auth views)

心已入冬 提交于 2020-01-12 07:06:06
问题 I´m working on a course exercise and I'm stuck for a few hours and I'm not sure what is causing the app to break, next, you will find the files involved and perhaps you can find out the solution. Thanks for your help! Project structure This error is being thrown when I log in: Internal Server Error: /account/login/ ... django.urls.exceptions.NoReverseMatch: Reverse for 'dashboard' not found. 'dashboard' is not a valid view function or pattern name. [04/Apr/2018 17:12:15] "POST /account/login/

Django pass object from view to next for processing

会有一股神秘感。 提交于 2020-01-12 05:25:17
问题 If you have 2 views, the first uses modelform that takes inputted information from the user (date of birth, name, phonenumber, etc), and the second uses this information to create a table. How would you pass the created object in the first view to the next view so you can use it in the second view's template I'd appreciate any help you can share 回答1: One approach is to put the object into a session in your first view, which you could then retrieve from the request.session in the second view.