Tagged Questions
22
votes
11answers
17k views
Python: How to find script's directory
Consider the following python code:
import os
print os.getcwd()
I use os.getcwd() to get the script file's directory location. When I run the script from the command line it gives me the correct ...
22
votes
1answer
4k views
How do I use Logging in the Django Debug Toolbar?
I would like to output debug messages in my django app at different points in a view function. The docs for the django-debug-toolbar say it uses the build in python logging but I can't find any more ...
12
votes
1answer
2k views
Test Django views that require login using RequestFactory
I'm new to Django and I'd like to unit test a view that requires the user to be logged in (@login_requred). Django kindly provides the RequestFactory, which I can theoretically use to call the view ...
9
votes
5answers
2k views
django-admin: Add extra row with totals
I'm using the standard django admin module to display a list of rows. One of the columns is a numerical field. I'd like to display an extra 'totals' row that has most of the columns as blank, except ...
9
votes
4answers
7k views
Django - Getting last object created, simultaneous filters
Apologies, I am completely new to Django and Python.
I have 2 questions. First, how would I go about getting the last object created (or highest pk) in a list of objects? For example, I know that I ...
9
votes
1answer
269 views
Why do django templates render dictionaries so slowly?
When I render a moderately complex dictionary (4 levels deep, ~2K data points) using django 1.4's default template system the template rendering step takes over 2800ms. When I do html-gen directly ...
7
votes
4answers
15k views
Django Foreign key queries
In the following model:
class header(models.Model):
title = models.CharField(max_length = 255)
created_by = models.CharField(max_length = 255)
def __unicode__(self):
return ...
7
votes
3answers
3k views
Django language codes
What is the link to find the list of languages i.e, language_code
(Swedish,sv)
(English,en) ..........
Please provide the link
Thanks..
7
votes
1answer
930 views
Django Passing data between views
I was wondering what is the 'best' way of passing data between views. Is it better to create invisible fields and pass it using POST or should I encode it in my URLS? Or is there a better/easier way ...
6
votes
2answers
4k views
Django check for any exists for a query
In django how to check whether any entry exists for a query
sc=scorm.objects.filter(Header__id=qp.id)
This was how it was done in php
if(mysql_num_rows($resultn))
{
}
...
6
votes
1answer
2k views
Why am I getting this error, "'NoneType' object has no attribute 'csrf_exempt'?
I am attempting to invoke /save_calendar, mapped to pim_calendar.save_calendar(), which begins:
@csrf_exempt
@login_required
def save_calendar(request):
...
6
votes
3answers
281 views
Display table of objects django
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 ...
5
votes
2answers
8k views
matching query does not exist Error in Django
HI..I have implemented a password recovery functioanlity in django. With my method the new password will be sent to his email id entered. And its working fine when i give the correct email (e-mail id ...
5
votes
3answers
1k views
How to send a session message to an anonymous user in a Django site?
I often show messages about user actions to logged in users in my Django app views using:
request.user.message_set.create("message to user")
How could I do the same for anonymous (not logged in) ...
5
votes
2answers
463 views
Getting all items less than a month old
Is there a way to get all objects with a date less than a month ago in django.
Something like:
items = Item.objects.filter(less than a month old).order_by(...)