django-templates

Changing image in django user change form

心不动则不痛 提交于 2020-06-17 13:05:10
问题 I am making a django webapp where users can upload profile image. I have also created an EDIT PROFILE page by using the default USERCHANGEFORM . But the problem is, that I cannot update the profile picture from that form. I can delete it but not upload new one? Help needed. This is my USER CREATION FORM : class SignUpForm(UserCreationForm): photo = forms.ImageField(required=False) bio = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Enter your bio'})) designation = forms

django modelform with bootstrap

放肆的年华 提交于 2020-06-11 11:46:10
问题 I want to format my modelforms with bootstrap, and without any additional packages (just using the bootstrap source files). A particular form that I want configured: class FoodForm(forms.ModelForm): class Meta: model = Food fields = ['name', 'company'] exclude = ('user', 'edit') The 'name' is a text field I'd want to be a bootstrap text field, and 'company' is a selection field (from a foreign key) that I'd want to be a bootstrap dropdown. The current setup of the form template: {% extends

django modelform with bootstrap

独自空忆成欢 提交于 2020-06-11 11:46:07
问题 I want to format my modelforms with bootstrap, and without any additional packages (just using the bootstrap source files). A particular form that I want configured: class FoodForm(forms.ModelForm): class Meta: model = Food fields = ['name', 'company'] exclude = ('user', 'edit') The 'name' is a text field I'd want to be a bootstrap text field, and 'company' is a selection field (from a foreign key) that I'd want to be a bootstrap dropdown. The current setup of the form template: {% extends

Get all templates django detects from TEMPLATE_LOADERS and TEMPLATE_DIRS

限于喜欢 提交于 2020-06-09 12:59:50
问题 TEMPLATE_DIRS = ('/path/to/templates/',) TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) I'm trying to find a solution that would list the contents of my specified directory in either of these locations ( TEMPLATE_DIRS or TEMPLATE_LOADERS ). I need something like: template_files = [] for dir in EVERY_DIRECTORY_DJANGO_LOOKS_FOR_TEMPLATES_IN: template_files.append(os.listdir(dir)) 回答1: Since templates can be in nested

Could not parse the remainder

孤人 提交于 2020-06-09 11:58:07
问题 i want to compare num and {{buildSummary_list.number}}, but why it is not work? And i got an error Could not parse the remainder: '{{buildSummary_list.number}}' from '{{buildSummary_list.number}}'"... {% for num in buildSummary_list.paginator.page_range %} {% ifequal num {{buildSummary_list.number}} %} <b>{{num}}</b> {% endifequal %} {% ifnotequal num {{buildSummary_list.number}} %} <a href="?page={{num}}"><b>{{num}}</b></a> {% endifnotequal %} {% endfor %} I want to make the pagination have

Use Django template syntax in a css file

我与影子孤独终老i 提交于 2020-06-08 07:56:07
问题 I have a css file home_global.css which has the following in it: body { background-image: url("{% static 'citator/citator.jpg' %}"); } This static file is loaded using: <link rel="stylesheet" href="{% static 'citator/home_global.css' %}" type="text/css"> However the url of the background-image, expectedly, doesn't resolve but is parsed literally. What I would like to do is enable Django template syntax in the css file. Please note that the static URLs etc are all set up correctly and this

Django how to link to some part of a page

不问归期 提交于 2020-06-01 03:59:07
问题 I want a link in my webpage header bar that points to a certain part of a page (for example, the lower half). It's easily done with pure HTML but I wonder how to do it in django. HTML version: In base.html: <a href="/entrance.html#intro">Introduction</a> In entrance.html: <a name="intro"></a> How can I do the same thing in django? Any better solutions than just writing one more view function? 回答1: There is no difference in doing it with Django when compared to just normal HTML. Just continue

Django how to link to some part of a page

倖福魔咒の 提交于 2020-06-01 03:58:04
问题 I want a link in my webpage header bar that points to a certain part of a page (for example, the lower half). It's easily done with pure HTML but I wonder how to do it in django. HTML version: In base.html: <a href="/entrance.html#intro">Introduction</a> In entrance.html: <a name="intro"></a> How can I do the same thing in django? Any better solutions than just writing one more view function? 回答1: There is no difference in doing it with Django when compared to just normal HTML. Just continue

django template access to list item by forloop.counter

女生的网名这么多〃 提交于 2020-05-31 03:42:11
问题 I want to loop over my model's query set in the Django template. I can do it simply using Django for loop but I can not do it for steps more than 1,Here is my code {% for map in maps %} {% if forloop.counter|divisibleby:2 %} #Here I can access Maps with index of 1,3,5 and .. #How can I access map with index 2,4,6 here at the same time sth like Map[forloop.counter+1] {% endif %} {% endfor %} In fact I want a way to acces Map[forloop.counter+1] in my template but I have no idea how to do that

Splitting a list with django template tags

若如初见. 提交于 2020-05-23 04:46:12
问题 I have a single list my_list in my context, and I'd like to render it as two "columns", with the first (n+1)/2 items in the first column and the last n/2 items in the second column. Is there a straight-forward way to do this with django template tags/filters or do I need to pre-split the list into two in my view? e.g., <div class="split-50-left"> <ul> {% for item in [first half of my_list] %} <li>{{item}}</li> {% endfor %} </ul> </div> <div class="split-50-right"> <ul> {% for item in [second