django-templates

Django pagination and object list show 404 page

Hi guys, i would like to paginate my object list, im tring to use django-pagination, but is showing a 404 page no found when i try to navigate. ulr.py categoria_info = { 'queryset':Categoria.objects.all(), } urlpatterns = patterns('', url(r'^$', object_list, ...

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

Hi All, 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.mo...

Django template dir switching

Does anyone know a way to switch the TEMPLATE_DIR in django dynamically. I need to create a set of templates for a mobile version and would like the templates to sit inside there own dir instead of inside the root template dir ie: I would like 2 template dirs 'templates' and 'mobile_templates' and not have to use 'templates/mobile' for ...

How to conditionally skin an existing site (for partner branding)

I've got an existing Django site, with a largish variety of templates in use. We've agreed to offer a custom-skinned version of our site for use by one of our partners, who want the visual design to harmonize with their own website. This will be on a separate URL (which we can determine), using a subset of the functionality and data fr...

Django : How do I call "reverse" on a link to a static image file?

In Django, I have images stored in site_media like this : /site_media/somepath/image.jpg The urls.py file has been set up to server these using : urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'staticfiles.views.serve') ) urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'staticfiles.views.serve') ) So...

what happen with this django-template if tag ?

Sorry if I am being a moron, but what happen with this if tag ? view return: return render_to_response('productos/por_estado.html', {'productos':productos}, context_instance=RequestContext(request)) #Im not returning 'estado' ! template: {% if estado %} {% block activos_active %}class="active"{% endblock %} {% en...

Creating a news archive in Django

Hi need some help, I looking to build a news archive in python/django, I have no idea where to start with it though. I need the view to pull out all the news articles with I have done I then need to divide them in months and years so e.g. Sept 09 Oct 09 I then need in the view to some every time a new news article is created for a new...

Django - accessing the RequestContext from within a custom filter

I've got a filter currency, which takes a value in USD and converts it to a currency (either USD or GBP). The currency to convert to is stored in the session, but filters don't take RequestContext, so I can't grab it straight from there. Is there a better way than passing the relevant session element into the template, and from the temp...

Get list values in a Django Template

In view: return render_to_response('template.html', {'headers': list(sort_headers.headers()) }, context_instance=RequestContext(request)) In template: {{ headers }} <br /> {{ headers|slice:"1" }} In browser: [{'url': '?ot=desc&amp;o=0', 'text': 'Nombre', 'class_attr': ' class="so...

Print a template variable on an overwritten admin form in Django

I have a Doctor-model which has a field called first_created. It is just a DateField that is auto_add_now, hence it is not displayed when editing a doctor in the admin interface. I want to display this field on the admin interface, at the top of the site as say, a static or something. It is supposed to ease the process of typing in dat...

django query db on every request

i have a navigation element that is determined by values in a database. no matter what view it is, i need to get these navigation objects out of the database. where in the code can i tell it to set a template variable containing all the navigation objeccts without setting it in every view? ...

Why is my django template context processor not getting called

I must have missed something in setting up a custom template context as it's never getting called. In settings: TEMPLATE_CONTEXT_PROCESSORS = ( "django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django_authope...

A way to use method parameters in django templates?

I know there is a post here: http://stackoverflow.com/questions/1333189/django-template-system-calling-a-function-inside-a-model describing how you can make a custom template filter to achieve this, but from a programmer's standpoint this is a failure because that's hacking something that isn't meant for that. It seems almost ridiculous ...

Redirecting in Admin Site

I have an app called CMS with Category and Article. Quite simple. I overwrite app_index.html to enable ajax-based drag-n-drop ordering and to move articles from one category to another. Now I would like to redirect after saving/deleting an article or a category to cms' app_index.html instead of the model's change_list.html. How can thi...

Present data from python dictionary to django template.?

I have a dictionary data = {'sok': [ [1, 10] ], 'sao': [ [1, 10] ],'sok&sao':[ [2,20]] } How Can I (Loop trough Dictionary ) present My data as (HTML) table to Django template.?? This format that as table author qty Amount sok 1 10 sao 1 10 sok...

How do I inject actual html from the model to the template?

In my admin, I have a text area where the user can input html: <ul> <li>blah</li> </ul> <p> Stuffs </p> When I push the above to my template and I view the source of the page, I get: &lt;ul&gt; &lt;li&gt;blah&lt;/li&gt; &lt;/ul&gt; &lt;p&gt; Stuffs &lt;/p&gt; What should I do with my output so that I see actual html in the ...

how to know if checkbox is checked having just the {{ form.checkbox }} form-tag

how to know if checkbox is checked (True, 1) having just the {{ form.checkbox }} form-tag? activo is True, 1 in db. my template is: {{ form.activo }} RESULTS: <input id="id_activo" type="checkbox" name="activo" checked="checked"/> {{ form.activo.data }} RESULTS: False {{ form.activo.value }} RESULTS: "" No 1 or True's :S Any hint...

How to create a specific if condition templatetag with Django ?

Hello, My problem is a if condition. I would like somethings like that but cannot figure out how to do it. {% if restaurant.is_favorite_of(user) %} <img src="{{MEDIA_URL}}images/favorite_on.png" alt="This restaurant is one of your favorite (Click to undo)" /> {% else %} <img src="{{MEDIA_URL}}images/favorite_off.png" alt="Th...

Use Choices from Models in a template tag

Hi Guys, I have a model with a bunch of choices, that are in the DB configured as below. COL_CHOICES =( (1, 'Not Applicable'), (2, 'Black'), ) COL2_CHOICES =( (1, 'Green'), (2, 'Blue'), ) etc. I want to display all these options as a menu in my templates, (to be used ...

ManyToManyField present in template?

I have 03 models book->target_readers and book has collection. class Book(models.Model): def __unicode__(self): return "%s (%s)" % (self.title, self.reference) reference = models.CharField(max_length=100) title = models.CharField(max_length=200) collection = models.ForeignKey(Collection) class Collection(models....