Hi .. im wondering how to make some posted texts be deleted on some certain date/time on a django site. Is it done with scripts to delete content in the database?
I need to serve images securely to validated users only (i.e. they can't be served as static files). I currently have the following Python view in my Django project, but it seems inefficient. Any ideas for a better way?
def secureImage(request,imagePath):
response = HttpResponse(mimetype="image/png")
img = Image.open(imagePath)
img.save(response,'png')
return response
(Image is imported from PIL.)
In PHP you can create form elements with names like:
category[1]
category[2]
or even
category[junk]
category[test]
When the form is posted, category is automatically turned into a nice dictionary like:
category[1] => "the input value", category[2] => "the other input value"
Is there a way to do that in Django? request.POST.getlist isn't quite right, because it simply returns a list, not a dictionary. I need the keys too.
I know you can override delete and save methods in DJango models, but can you override a select query somehow to intercept and change a parameter slightly. I have a hashed value I want to check for, and would like to keep the hashing internal to the model.
I have a string of HTML stored in a database. Unfortunately it contains characters such as ®
I want to replace these characters by their HTML equivalent, either in the DB itself or using a Find Replace in my Python / Django code.
Any suggestions on how I can do this?
Hi
How to restrict the size of file being uploaded.
I am using django 1.1 with apache.
Can I use apache for this and show some html error page if say size is bigger then 100MB.
Thanks.
Hello!
I want to enable debug (DEBUG = True) For my Django project only if it runs on localhost. How can I get user IP address inside settings.py? I would like something like this to work:
#Debugging only on localhost
if user_ip = '127.0.0.1':
DEBUG = True
else:
DEBUG = False
How do I put user IP address in user_ip variable inside settings.py file?
Hay, how do i find a value with in python list in django's template system?
example
list = [1,2,3,4,5,6,7]
x = 1
if x is in list:
return u'found!'
else:
return u'not found'
endif:
Something along those lines.
any help would be great
I'm trying to set up a proxy model in django admin. It will represent a subset of the original model. The code from models.py:
class MyManager(models.Manager):
def get_query_set(self):
return super(MyManager, self).get_query_set().filter(some_column='value')
class MyModel(OrigModel):
objects = MyManager()
class Meta:
proxy = True
Now instead of filter() I need to use a complex SELECT statement with JOINS. What's the proper way to inject it wholly to the custom manager?
I have a Django based site on Nginx+FastCGI which keeps running into "504 timeout error" after about 30 minutes since FastCGI process restarted. I did a "ps -aux" check and a lot of FastCGI processes are with D status.
How can I figure out which part of the site make FastCGI processes not responsing?
I would basically like to do the same as this question, but grouping by combinations of two values, rather than just one:
SELECT player_type, team, COUNT(*) FROM players GROUP BY player_type, team;
Does anyone know whether, and how, this is possible in Django? I'm using 1.2.
Hello!
To empty database table, I use this SQL Query:
TRUNCATE TABLE `books`
How to I Truncate table using Django models and orm?
I've tried this, but it doesn't work:
Book.objects.truncate()
I just started django and i want to access images uploaded by a user.
here is my model:
class Food(models.Model):
name = models.CharField(max_length=100)
price = models.DecimalField(max_digits=4, decimal_places=2)
quantity = models.IntegerField(blank=True, null=True)
description = models.CharField(max_length=200)
location = models.CharField(max_length=100)
time = models.DateTimeField()
photo_thumbnail = models.ImageField(upload_to="images")
photo_fullsize = models.ImageField(upload_to="images")
i stored the image in the "images" folder below
the html is this:
img src="{{steak.photo_thumbnail}}"
and
steak.photo_thumbnail = images/steak_and_egg_thumbnail_1.png
here is the error i get:
[06/Jul/2012 19:08:24] "GET /menu/ HTTP/1.1" 200 99
[06/Jul/2012 19:08:24] "GET /menu/images/steak_and_egg_thumbnail_1.png HTTP/1.1" 404 2127
I have a pretty simple question. I want to make some date-based generic views on a Django site, but I also want to paginate them. According to the documentation the object_list view has page and paginate_by arguments, but the archive_month view does not. What's the "right" way to do it?
Hi,
i have a large dictionary I'd like to save. I have pickled it using cPickle.dumps and saved the result into a TextField. When trying to retrieve it (cPicle.loads) i get the following error:
loads() argument 1 must be string, not unicode
Does anybody have any experience in serializing python objects and storing them in a DB using Django? Thanks in advance.
It looks like Django does not update last_login field in auth_user model when a visitor is authenticated by saved session.
So in this case, how can I implement a similar feature like the "seen" field on very SO user's profile page.
Hi folks,
I need to setup temporary User models for each visitors, where the visitors are obviously tied by session data.
I might not be aware of it, but does Django support attaching data to Anonymous users?
The only way, I am currently aware of, is to use the session dictionary part of the request object.
Help would be very much appreciated!
The Django documentation gives en example like so:
b = Blog.objects.get(id=1)
b.entry_set.all()
Which from what I understand results in 2 queries. What if I wanted to get the blog, the blog entries and all the comments associated with that entry in a number of queries that does not depend on the number of entries? Or do I have to drop down to SQL to do that?
I'm running Apache, mod_wsgi and Django. Uploading a file over 100mb causes a timeout on IE 7 and 8, but successfully uploaded on Firefox 3.5. Specifically the error is "Internet Explorer cannot display the webpage". The timeout is not immediate, it runs for quite some time before it fails. Any suggestions?
UPDATE: I set TimeOut to 1200 and it made no difference
Im wonder how to set the language code inside a view (in django).
Im sending a HttpResponse that contains a python-date.strftime("%A") %A = The day (ex: Monday). But I want to get the day in swedish instead of english.
i wonder if ruby on rails have bundles, the ones similar in django?
kind of a plugin that contains css, js, images, ruby code and everything for one feature.
thanks
Now that I've gotten relatively familiar with web2py, I'd like to give Django a go.
What are the main differences?
What would be the most efficient way to get started taking into account web2py knowledge?
(It must help to have some python application framework knowledge,no?)
EDIT
Also, if you've used both, can you offer an opinion on which you prefer and why?
Is there any way to get a backend-neutral dictionary cursor in Django? This would be a cursor that is a dict rather than a tuple. I am stuck using Oracle.
in Python's MySQLDb module it's called a DictCursor..