django-templates

Django-grappelli admin: No reverse match error

孤人 提交于 2019-12-05 00:17:12
I've been working on a django project for a while now that uses grappelli for the admin and all of a sudden today my change_form.html template is throwing the following error: Caught NoReverseMatch while rendering: Reverse for "grp_related_lookup" with arguments '()' and keyword arguments '{}' not found. The offending line of code is line 38: 37 $.each(related_lookup_fields_fk, function() { 38 $("#id_" + this).grp_related_fk({lookup_url:"{% url grp_related_lookup %}"}); 39 }); which is preceded by this bit of code: var related_lookup_fields_fk = {% get_related_lookup_fields_fk adminform.model

Client-Side (JavaScript) Django/Jinja-like template inheritance

心不动则不痛 提交于 2019-12-05 00:02:13
I'm looking for a way to do template inheritance to a group of .html files I have. Let's say I have a base.html file which has the common HTML for all pages of my website, i.e. header, footer, etc. . Each page, including the main (index) page, needs to inherit from this template HTML file. Now, this is doable on the server-side using Django's Jinja template langauge . But this is not a good solution for me. My HTML pages are stored remotely and I have no control over the server storing them. This must be done client-side, with or without JavaScript. Somebody asked about this before , and the

initial value for django form choice field ignored

时光总嘲笑我的痴心妄想 提交于 2019-12-04 23:46:13
I have this form: class UserUsesSourceForm(forms.Form): # some fields here username = forms.CharField(label=("Username"), max_length=30, help_text = ("Required")) provider = forms.ChoiceField(widget=forms.Select(), choices=SOURCES_CHOICES, initial=SOURCES_CHOICES[1]) The available choices are: E = 'e' A = 'a' SOURCES_CHOICES = ( (A, 'A'), (E, 'E'), ) The view: form = UserUsesSourceForm(initial={"username":request.user.username, 'provider':SOURCES_CHOICES[1]})return render_to_response('update_datasource.html', context_instance=RequestContext(request, params)) And the template: <form action=""

Django output form errors as table rows in {{ form.as_table }}

左心房为你撑大大i 提交于 2019-12-04 23:45:30
问题 I really find the form output shortcuts such as as_table really handy. However, displaying errors while using those methods seems a little counterintuitive to me. When I use the as_table format, I would like my field specific errors to be displayed in accordance to table formatting. I can manually piece my forms together like so: <table> {% for error in form.non_field_errors %} <tr><td>{{ error }}</td></tr> {% endfor %} {% endif %} {% if form.username.errors %} {% for error in form.username

Django 'ascii' codec can't encode character

心已入冬 提交于 2019-12-04 22:56:27
In Django I want to use a simple template tag to truncate data. This is what I have so far: @register.filter(name='truncate_simple') def truncate_char_to_space(value, arg): """ Truncates a string after a given length. """ data = str(value) if len(value) < arg: return data if data.find(' ', arg, arg+5) == -1: return data[:arg] + '...' else: return data[:arg] + data[arg:data.find(' ', arg)] + '...' But when I use it I get the following error: {{ item.content|truncate_simple:5 }} Error: 'ascii' codec can't encode character u'\u2013' in position 84: ordinal not in range(128) Error is on line

Django form multiple select box size in template

淺唱寂寞╮ 提交于 2019-12-04 22:04:14
问题 I have a template: ... <form action="/reportform/" method="post"> <p><label>Aircraft system:</label> <br>{{ Querry.system }} ... it looks like this How can I set a Size option for this box? for example, 10. 回答1: Use the attrs attribute to define the size. class MyForm(forms.Form): system = forms.ChoiceField(choices=SYSTEM_CHOICES, widget=forms.SelectMultiple(attrs={'size':'40'})) Sometimes, it is useful to override the widget in the forms init method. class MyForm(forms.Form): <snip> def _

Django - Rating Model Example DetailView Template

北战南征 提交于 2019-12-04 21:46:34
Here is the context: I have users, videos, topics, criterias and ratings A video has a topic A topic has criterias A user can create a video for a given topic A user can rate a video on the criterias given for the concerned topic. Here is my model for that purpose: RATE_CHOICES = zip( range(1,5), range(1,5) ) class VideoCrit(models.Model): """Criteria to rate videos on. Can be multiple for each Topic of Video""" name = models.CharField(max_length=50) def __unicode__(self): return self.name class Meta: verbose_name = 'Video Criteria' class VideoTopic(models.Model): name = models.CharField(max

Display table of objects django

巧了我就是萌 提交于 2019-12-04 21:45:04
问题 I need to display a table from my database with Django. The obvious way is to manually type in the table headings and loop through query results of model.objects.all() . However, being quite lazy, I want to do this automatically, i.e. load all fields from model through introspection to display as column headings and load all field values to display as rows. This approach can also save me some time later because I don't have to update my template code when my model changes. I got it to work

django serving static css files

强颜欢笑 提交于 2019-12-04 20:49:23
I am relatively new to Django development.I have a css file inside a /static/css directory. When I try to run the url no CSS is applied to my template. the python manage.py runserver window shows following error [01/Jan/2013 20:00:40] "GET /home/prat/PROJECT_ROOT/SOURCE_ROOT/static/css/Style.css HTTP/1.1" 404 2207 Can someone please point me how to debug this. I have read multiple stackoverflow questions and added the following setting in my settings.py. PROJECT_R = os.path.abspath(os.path.dirname(__name__)) PROJEECT_R = PROJECT_R + "../" STATIC_ROOT = os.path.join(PROJECT_R, "static") STATIC

Rendering custom template tags from database in Django

瘦欲@ 提交于 2019-12-04 19:34:50
I am pretty new to Django and am trying to build a blog app for my website. I have a model I have created to store blog posts that includes a text field for the post body, created and converted to HTML using TinyMCE (via Grappelli). I would like embed custom template tags within this post body that are saved in the database as the template tag, but then rendered as HTML when requested on my site. So far, I am not having any luck getting the tags to render properly. How can I get Django to correctly interpret and render the template tags within my post? The custom tag works fine when loaded and