django-templates

Check if a variable is defined in django templating language [closed]

ⅰ亾dé卋堺 提交于 2019-12-05 06:24:33
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am using django 1.5, I need to check if a variable is defined (and have it not work if the variable is defined but None, 0, "", etc...). Something like: {% ifexists a_variable %} <p> Hey the variable exists </p> {% endifexists %} I don't how best to do this... Please read the documentation . The {% if %} tag evaluates a variable, and if that variable is “true” (i.e. exists ... {% if athlete_list %} Number of

Django admin page error

☆樱花仙子☆ 提交于 2019-12-05 06:24:33
问题 I was creating a Django app. Doing so i enabled the Django admin site and i could see it working fine. Then i created some models and inserted data into it through the form in my app. But i am not able to see the entered values through admin panel of Django. I found that its because i havent included an admin.py file in my application folder. Then i created an admin.py file, ran syndb and tried. Now its throwing an error ImportError at /admin/ No module named UniversityDetails.models I will

Django template outliner

给你一囗甜甜゛ 提交于 2019-12-05 06:09:59
问题 I'm trying to obtain a visual representation of the templates of a Django project, as a hierarchy. The main idea is to get a list of template names as the default template loading machinery would return (ie honoring TEMPLATE_DIRS , TEMPLATE_LOADERS , etc.) and then parsing the templates looking for {% block %} and {% extends %} tags, in order to create a tree structure. Finally use grapviz for the visualization. I'm not sure if it's a viable approach. But just to start, how can I load the

How To Use Django Cycle Tag

帅比萌擦擦* 提交于 2019-12-05 05:58:18
This hopefully is a pretty easy question. My endgoal is to be able to view my database entries in a table which I can sort via the column headers. I have read the documentation on cycle tags, but don't know they mean by 'row1' and 'row2' : {% for o in some_list %} <tr class="{% cycle 'row1' 'row2' %}"> ... </tr> {% endfor %} Secondly, how would I correctly implement it into my template? I am using a very simple JS library , which will allow the sorting: page.html {% if Variable %} <table class="sortable"> <tr> <th>Title 1</th> <th>Title 2</th> <th>Title 3</th> <th>Title 4</th> <th>Title 5</th>

Access form field attributes in templated Django

时光毁灭记忆、已成空白 提交于 2019-12-05 05:24:14
I've been doing some custom forms with django but I don't get how to access attributes that a specific form field has attached via the forms.py. def putErrorInTitle (cls): init = cls.__init__ def __init__ (self, *args, **kwargs): init(self, *args, **kwargs) if self.errors: for field_error in self.errors: self.fields[field_error].widget.attrs['title'] = self.errors[field_error][0] self.fields[field_error].widget.attrs['class'] = "help_text error_field" cls.__init__ = __init__ return cls That's how I attached the attibutes to the field. <dl class="clearfix two"> <dd> <label for="id_diagnosis"

Is it safe to render user-created Django templates?

做~自己de王妃 提交于 2019-12-05 05:13:48
Is it safe to let users make their own Django templates with a set of pre-defined variables, and then render this template on the server? I would only pass a very limited set of parameters to render , all of which are strings. Templates would be something like: hey, my name is {{name}}. So, the question is, are there any django template tags that can be abused to get information that users are not supposed to get? I'm most worried about the {% url %} tag. P.S. I noticed this question after filling out the title, however, my question is slightly different. I will probably allow no HTML

How to truncate html without breaking the tags?

瘦欲@ 提交于 2019-12-05 04:32:13
How to ensure that all html-tags were closed? The problem arises because I want create some sort of excerpt for every article. For example someone writes an article like this: Hi everyone, I'm just an article and I have few <strong>tags</strong> inside <em>of me</me> If I cut this message just after "tags", I get an unclosed tag . How can I check with Django all user's input text before saving it to DB? In Django 1.7, there is a specific template filter called truncatechars_html : Similar to truncatechars, except that it is aware of HTML tags. Any tags that are opened in the string and not

save multiple uploaded files in django

人盡茶涼 提交于 2019-12-05 03:54:19
I want to upload and save multiple files in my application, I have <input type="text" name="name" value="" /> <input type="file" name="file" multiple/> in my template. when I hit upload, seems form = MyForm(request.POST, request.FILES) is only saving one file which is last in the list of the many uloaded files. How can I be able to save all the uploaded files using the form form = MyForm(request.POST, request.FILES) blah blah ? Thanks Edit Myform is a model form from this model. class Docs(models.Model): name = models.CharField(max_length=128) file = models.FileField(max_length=100, upload_to=

Proper way to handle multiple Django forms in one page with two views?

 ̄綄美尐妖づ 提交于 2019-12-05 03:42:50
问题 I've struggled with this problem for the last two days and could use some help. The home page for my Django 1.6 application will include two forms, one that a user can use to sign in to the site and one they can use to sign up (create a login) for the site: # templates/home/home_page.html <div class="sign-in-form"> <form action="{% url 'apps.home.views.sign_in' %}" method="post"> {% csrf_token %} {{ sign_in_form.as_p }} {% if next %} <input type="hidden" name="next" value="{{ next }}"> {%

How to make master-detail model / screen in Django?

北慕城南 提交于 2019-12-05 03:27:29
问题 One thing that I allways collide is how to implement a master-detail application with Django. The tipical example is the Invoice and InvoiceLines. The things to discuss are: how to structure code for saving, loading, etc. master and detail models views: files and templates, templates for detail lines, how to add dynamically autocalculated fields (like the total on parent row), where this code goes ? Edit/Additions: About autocalculated fields, here is my first solution, http://pastebin.com