django-templates

How do I use request.META.get('HTTP_REFERER') within template?

天涯浪子 提交于 2019-12-10 02:11:58
问题 I'd like to use request.META.get('HTTP_REFERER') within template. My template source: <!-- this is login.html --> {% extends "base.html" %} {% block title %}django bookmark- login{% endblock %} {% block head %}login{% endblock %} {% block content %} {% if form.errors %} <p>try again!</p> {% endif %} <form method="post" action=".">{% csrf_token %} <p><label for="id_username">username:</label> {{ form.username }}</p> <p><label for="id_password">password:</label> {{ form.password }}</p> <input

Using safe filter in Django for rich text fields

£可爱£侵袭症+ 提交于 2019-12-10 01:56:39
问题 I am using TinyMCE editor for textarea fileds in Django forms. Now, in order to display the rich text back to the user, I am forced to use the "safe" filter in Django templates so that HTML rich text can be displayed on the browser. Suppose JavaScript is disabled on the user's browser, TinyMCE won't load and the user could pass <script> or other XSS tags from such a textarea field. Such HTML won't be safe to display back to the User. How do I take care of such unsafe HTML Text that doesn't

Problem loading custom template tags (Error: No module named x)

做~自己de王妃 提交于 2019-12-10 01:55:06
问题 I am currently writing a few custom template tags but for some reason they will not load. My directory structure is as follows: MyProj | ----MyApp | |----templatetags | |----myapp_tags.py |----__init__.py In myapp_tags.py from django.template import Library, Node from myproj.myapp.models import Product register = Library() class LatestProductsNode(Node): def render(self, context): context['recent_products'] = Product.objects.all()[:5] return '' def get_latest_products(parser, token): return

Django CSRF token won't show

纵饮孤独 提交于 2019-12-10 01:06:56
问题 Here's the relevant snippet of HTML in the template: <form action="/submit_text/" method="post"> {% csrf_token %} {% include "backbone/form_errors.html" %} {{form.as_p}} <input type="submit" value="Submit" /> </form> Here is my settings.py MIDDLEWARE_CLASSES declaration: MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware

How to create dynamic ids for tags in django templates

随声附和 提交于 2019-12-09 19:39:51
问题 Background: I have a dynamic table (as in I don't know its size/elements until runtime) where I am trying to populate a text area with a javascript function. To do this I plan on passing the text area's id along with the values I want to populate it with into the javascript function. The problem is I am having trouble creating a dynamic id value for each text input field. This is how i am currently attempting to do this: {% with "input_"|add:applicant.id as idName %} <input id="{{ idName }}"

Django 500 message in custom template

风流意气都作罢 提交于 2019-12-09 15:10:19
问题 I have a 500.html template which gets loaded whenever my app explodes but I wanted to know if there's any way I can output the exception's message in the template? So if I do this: raise Exception("You broke it!") This will load 500.html when the DEBUG flag is set to True but how can I access the exception message in the template? Something like: {{ exception.message }} Many thanks. G 回答1: Have a look at this answer: How do I include a stacktrace in my Django 500.html page? It's not good to

Tell django to search app's template subfolders

此生再无相见时 提交于 2019-12-09 13:00:02
问题 I have the following folder structure for the templates on my django app: templates/ app/ model1/ model1_form.html model2/ model2_form.html Suppose I'm using model1 and a generic ListView, right now it only searches at templates/app/model1_form.html. Is there anyway I can tell django he should also search the app/ subfolders? I don't want to have to set the template name and path manually ( template_name="templates/app/model1/model1_form.html" ). At settings.py I have: import os.path BASE

Obtain the first part of an URL from Django template

早过忘川 提交于 2019-12-09 08:23:32
问题 I use request.path to obtain the current URL. For example if the current URL is "/test/foo/baz" I want to know if it starts with a string sequence, let's say /test. If I try to use: {% if request.path.startswith('/test') %} Test {% endif %} I get an error saying that it could not parse the remainder of the expression: Could not parse the remainder: '('/test')' from 'request.path.startswith('/test')' Request Method: GET Request URL: http://localhost:8021/test/foo/baz/ Exception Type:

How can I tell Django templates not to parse a block containing code that looks like template tags?

岁酱吖の 提交于 2019-12-09 08:21:35
问题 I've got some html files that include templates to be used by jQuery.tmpl. Some tmpl tags (like {{if...}} ) look like Django template tags and cause a TemplateSyntaxError. Is there a way I can specify the Django template system should ignore a few lines and output them exactly as they are? 回答1: As of Django 1.5, this is now handled by the built-in verbatim template tag. In older versions of Django, the built-in way would be to manually escape each template item with the templatetag template

bootstrap 3 wrap text content within div for horizontal alignment

ぃ、小莉子 提交于 2019-12-09 07:28:36
问题 My post title here could be misleading. first have a look at HTML i have currently: As you can see, each column's text content overflows to next column. Secondly, each of them is not horizontal aligned. (eg the link for view details does not align straight). I want them to be aligned straight irrespective of length of text. Here is my HTML code: (the content here is dynamically generated. so the no of items will vary). I use bootstrap 3 in my code. <div class="row" style="box-shadow: 0 0 30px