I have this in my views.py Since I start using this import: from django.utils.translation import ugettext_lazy as _ at this line: message = _(‘This is a test message’) I get this error: Why? What am I doing wrong? Answer You can also create you own JSON encoder that will force __proxy__ to unicode. From https://docs.djangoproject.com/en/1.8/topics/serialization/ So now your code can
Tag: django
Django-queryset join without foreignkey
model.py What I want is to get id_noga where dzienrok=1234. I know that dziens should be but it isn’t and I can’t change that. Normally I would use something like but I don’t know how to join and filter those tables without foreignkey. Answer It’s possible to join two tables by performing a raw sql query. But for this case
Python Django send_mail newlines?
I’m using django send_mail like this: Gmail recieves this. And shows my newlines as one whole paragraph. Why? I would like three lines of text, not one. Answer Try sending your email as HTML instead of plain text. Use EmailMessage().
Django Simple Captcha image size
How can I change captcha image size and text padding in image? I read official docs and havn’t found any of those. Answer I have never used this app, but I’ve found in code something: So if you call captch_image with additional paramater scale, you can change the size. If you use urls for this app like You can change
How to properly use the “choices” field option in Django
I’m reading the tutorial here: https://docs.djangoproject.com/en/1.5/ref/models/fields/#choices and i’m trying to create a box where the user can select the month he was born in. What I tried was Is this correct? I see that in the tutorial I was reading, they for some reason created variables first, like so Why did they create those variables? Also, the MONTHS_CHOICES is in
GeoDjango GEOSException error
Trying to install a GeoDjango on my machine. I’m really new to Python and being brought into a project that has been a very tricky install for the other team members. I installed Python 2.7 and GEOS using brew, and running PSQL 9.2.4 but keep getting this error when I try to get the webserver running: Cant seem to find
sql “LIKE” equivalent in django query
What is the equivalent of this SQL statement in django? How do I implement this in django? I tried But that did not work. How do i implement this? Answer Use __contains or __icontains (case-insensitive): The SQL equivalent is @Dmitri’s answer below covers patterns like ‘pattern%’ or ‘%pattern’
Django Queryset Filter Missing Quotes
I have a list and I want to filter my Queryset when any of these items is found in a foreign table’s non-primary key ‘test’. So I write something like this: This returns an empty list. When I look at the SQL query it generated, I get: Whereas what it should have been is this: Without the quotes, SQLite3 believes
i18n_patterns: How come some user are accessing /en-us/ where what I have is /en/
I am using i18n_patterns for my URL and yesterday when I launched the live site I noticed through Google Analytics many people are accessing http://www.example.com/**en-us**/ instead of http://www.example.com/**en**/. I do not have http://www.example.com/**en-us**/ link anywhere on my site. Personally, when I try to access the site through http://www.example.com/ I am redirected to http://www.example.com/**en**/ which is the wanted behaviour. Also when
sqlalchemy generic foreign key (like in django ORM)
Does sqlalchemy have something like django’s GenericForeignKey? And is it right to use generic foreign fields. My problem is: I have several models (for example, Post, Project, Vacancy, nothing special there) and I want to add comments to each of them. And I want to use only one Comment model. Does it worth to? Or should I use PostComment, ProjectComment