django-templates

Two views in a Django page

旧城冷巷雨未停 提交于 2019-12-11 05:53:00
问题 I'm having problems displaying the input box of my page. On this same page I would like to have two views, one that accesses and retrieves data and the other a form. As it's an event sign-up page, the first view show the details of a specific event and the second is a view to remove a specific user from the event itself. My views.py def ShowSpecificEvent(request, eventslug): if request.method == 'POST': form = RemovalForm(request.POST) if form.is_valid(): event = Event.objects.get(slug

Django: How to pre-populate a form when using non-model data?

假如想象 提交于 2019-12-11 05:39:21
问题 In my case, the Django app is saving and getting user data to/from an external service via an API. I get an object with a number of user attributes, e.g. name, address, etc. For updating of such information I'm using Django's native forms, with the shorthand template format, say: {{ edit_account_form.as_p }} When I display the form to edit the information, I'd like to pre-populate it with the data from the user object. I know that I can pass the object into the template and render those

Accessing request.META.SERVER_NAME in template

旧巷老猫 提交于 2019-12-11 05:26:49
问题 I call a template like this from my view: return render_to_response('mytemplate.html', context_instance=RequestContext(request)) I'm trying to access the hostname of my current server (in this case, localhost ), but it just prints blank when I place {{request.META.SERVER_NAME}} in the template. In my settings.py file, I don't have any TEMPLATE_CONTEXT_PROCESSORS defined. I'm not sure if I need to specify anything there, or if that could solve the problem. 回答1: You have to add the request

Python/Django: Email template is not rendered. Shows html tags and doesn't convert entities

China☆狼群 提交于 2019-12-11 05:05:21
问题 I am sending emails using a template, but the template is not being properly rendered. It shows the html tags and doesn't render special chars. It does render the context, for example if I supply it with a "username":some_name then it will properly display the username when I do {{username}} my_template.html: <p>hello ø</p> In views: from django.core.mail import EmailMultiAlternatives from django.template.loader import get_template from django.template import Context t = get_template('my

Django crispy forms not loading CSS

微笑、不失礼 提交于 2019-12-11 04:56:47
问题 I saw this question on SO: Django crispy-forms cannot find CSS, and followed all of the suggestions in the accepted answer, i.e.: 'crispy-forms' is listed under INSTALLED_APPS I'm not running a production server, so I'm not sure the collectstatic option applied (although I did run it) Also: I am trying to use the bootstrap template pack, so I added CRISPY_TEMPLATE_PACK = 'bootstrap' into my settings.py file. When I load the form created by the example from https://gist.github.com/maraujop

objects.all() query not working

时光毁灭记忆、已成空白 提交于 2019-12-11 04:50:47
问题 I am trying to make a form for user creation through django. The user(henceforth developer) can choose from a list of supervisors to get himself registered. Problem is, I am not getting the list of all the supervisors from the query. When I use objects.get(), I receive an error that 2 objects were received. That means that the queries are getting the rows from the database. models.py from django.db import models class UserProfile(models.Model): name = models.CharField(max_length=50,verbose

user.is_authenticated always returns False for inactive users on template

佐手、 提交于 2019-12-11 04:46:21
问题 In my template, login.html , I have: {% if form.errors %} {% if user.is_authenticated %} <div class="alert alert-warning"><center>Your account doesn't have access to this utility.</center></div> {% else %} <div class="alert alert-warning"><center>Incorrect username or password!</center></div> {% endif %} {% endif %} What I am trying to do is, if after form submission, user is inactive then display a different error message and if user is simply not authenticated then display Incorrect

Django - inlineformset-factory (How to Edit)

痴心易碎 提交于 2019-12-11 04:41:18
问题 I saw many tutorials and questions in many foruns and websites. And when I search for "inline formset-factory" are many links appear. But few talk about how edit, with inline formset-factory. I have a problem in my project, I did it save, but when I will try edit, rise some errors This is my code class Dia_Producao(models.Model): id = models.AutoField(primary_key=True) diaTrabalho = models.CharField("Dia de Trabalho", choices=DIATRABALHO_CHOICES, blank=True, null=False, max_length=10)

Render Django-CMS plugins differently on different splaceholders/templates

六眼飞鱼酱① 提交于 2019-12-11 04:39:34
问题 Short version: I'd like to have the same kind of cmsplugin use different templates in different placeholders. Is this possible? Or, should I go and make my custom plugin? Long version: Using Django and Django-CMS and using the cmsplugin-video-youtube plugin, I have two youtube videos on the home page and they are styled using Foundation 4's grid system to be stacked one and then another below it and at a certain 'breaking point' of the browser's width, they will be side-by-side. This is all

Use variable in statement in template

本秂侑毒 提交于 2019-12-11 04:39:30
问题 I want to use a variable in {% include %} statement in django templates. Specifically, I am trying to include a template in another template and i need to generate and pass url to be used in a button. How can I achieve this? This is my troublesome part of form.html template: <div class="col-md-12"> {% url 'accountant:gp_taxes:delete_rate' pk=field.value as delete_url %} {% include 'includes/formset_inline.html' with delete_url=delete_url %} </div> and formset_inline.html : <a class="btn btn-s