django

How can I get the full/absolute URL (with domain) in Django?

Exactly the same as this question, but there must be a way to do it without the Sites module. That's just silly... I shouldn't need to query my DB to snag the URL! I want to use it with reverse(). ...

Django URL configuration

Hello, I have a purchase page, it can take an optional argument as a gift, if it is a gift, the view passes a gift form to the template and if not, a regular purchase form. my old regular url, which redirects to two seperate views: (r'^(?P<item>[-\w]+)/purchase/$', 'purchase_view'), (r'^(?P<item>[-\w]+)/purchase/gift$', 'gift_view'), ...

how to set django static image

I have a view and template called index.html. I have a image which is broken form.I saw django docs,which was n't clear to me. How do,i make my image to appear.I m asking ,while development.image is in ,this URL /home/logic/quote/hummingbird.gif' ...

Is it OK to do 302s for architecture in my web applciation?

For example, in my index(request): def index(request): if logged_in: return HttpResponseRedirect("/home_profile") else: return HttpResponseRedirect("/login") This way, when the user hits my home page...he is redirected appropriately. Is this a good architecture? Or will this cause caching problems, etc? ...

Django Admin popup functionality

This topic is fairly common (most explicitly detailed here: http://www.hoboes.com/Mimsy/hacks/replicating-djangos-admin/), but I'm still having trouble with it. I'm trying to use the "plus" button functionality used in the admin site where one can add an additional foreign key to a linked entry. In the admin site, a popup displays allo...

define the queryset of ModelMultipleChoiceField in the widget

Hi I'm using ModelMultipleChoiceField with a large number of objects. I want to show only the selected objects and let the user remove a choice with js. To add choices the user will open a popup similar to ManyToManyRawIdWidget. I can limit the queryset to the selected choices in the init of the form with: def __init__(self, *args, **...

Easy way to submit POST data from a hyperlink in Django? Equivalent of Rails' `button_to`?

Is there a quick way to submit (pre-defined) POST data from a hyperlink in a Django template? I've got an 'add this to my favourites' link on page. I'm currently doing this with a GET request, which obviously breaks all kinds of rules. I could manually build a form and have the link submit it with Javascript. I'm looking for an automat...

Scraping for a "preview" of a webpage - Python

Hi folks, I'm indexing a list of links, these links update quite often so I'm automating thumbnails for the sites. For most sites it's easy, as I just grab the biggest image on the page hoping it describes the content. But other times there are videos as main content of the page. Does somebody have tips with dealing with this? That...

Python PIL and StringIO

I'm trying to download images from URLs and pass them to PIL. I would like to use less resources as possible, especially RAM. What would the best way of dealing with this? I've had suggestions to use cStringIO. ...

Django flatpages raising 404 when DEBUG is False (404 and 500 templates exist)

I'm using Django 1.1.1 stable. When DEBUG is set to True Django flatpages works correctly; when DEBUG is False every flatpage I try to access raises a custom 404 error (my error template is obviously working correctly). Searching around on the internet suggests creating 404 and 500 templates which I have done. I've added to FlatpageFal...

Security error on attempted access to twisted rpc server from javascript in the same domain but served from different port

Hi, I have a django server that serves the basic site with user, auth etc and a twisted web server that 'should' deliver live content as json streams. Django server is running on 127.0.0.1:8080 Twisted 127.0.0.1:9897 The problem is that when ever I try to make an http request to twisted server from a page in the django site, I get a ...

Display value in Charfield for foreign key in django on error

Let's say I've got a model and it has a foreign key to another one. class ModelA(models.Model): field = models.CharField(max_length=100) class ModelB(models.Model): model_a = models.ForeignKey(ModelA) Than I've got this form: class FormB(models.ModelForm): model_a = forms.CharField(required=True) def clean(self): ...

Unable to get custom context processor to be invoked

I am trying to create a custom context processor which will render a list of menu items for a logged in user. I have done the following:- Within my settings.py I have TEMPLATE_CONTEXT_PROCESSOR = ( 'django.contrib.auth.context_processors.auth', 'mysite.accounts.context_processors.user_menu', ) Under the accounts submodule ...

how to search related items into ManyToManyField?

Actually have this model: class MusicFile(models.Model): file = models.FileField(upload_to="files") def exist_in_playlist(self, playlist_id): exist = False try: mp = PlayList.objects.get(id=playlist_id, items__id=self.id) exist = True except PlayList.DoesNotExist: pass...

How can I write a route/view/controller for a web framework which acts as a dumb proxy?

That is to say, let's say I'm writing something that's hosted on foo.com. I'd like it to be possible for a user who goes to foo.com/bar.com to be served up bar.com from foo.com and to be able to interact with bar.com (e.g. navigate to foo.com/bar.com/baz via point-and-click). I understand that this is what a proxy is supposed to do. I...

What can I do if django runserver seems to be caching my urls.py and settings.py?

I detected this problem when updating the patterns in URLConf and seeing that the new pattern wasn't matched anywhere. So, with urls.py I don't get anywhere when writing random lines on it, I mean, invalid code, and django doesn't throw any exception and serves the urls just fine. So I checked ROOT_URLCONF in settings.py, and it points...

Django models, signals and email sending delay

Hello I have added a signal to my model, which sends email to some email addresses once a model is saved (via models.signals.post_save.connect signal and send_mail for email sending). This idea still makes delay for the users, when they save the model at the site, they have to wait until all those emails are sent and thats when they re...

URL is changing, output - not! (django)

Hi! I'm new to django, so quetions may be a bit stupid... I've deploy my project on VDS with nginx+fastcgi. On dev server everything was OK, but on VDS every URL outputs the main page (pattern '^$'), even those, which not described in urls.py and may out 404. What is the problem? ...

Date fields and Django's loaddata

Can a date be loaded into a DateField using Django's loaddata admin feature? I have a JSON file that I'm using to bulk load data into my app. When you dumpdata, date fields are outputted in the format yyyy-mm-dd. However, if you try loading data back in with the same format, the field is treated as a string and the load fails. For ex...

Django LowerCaseCharField

We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions. from django.db.models.fields import CharField class LowerCaseCharField(CharField): """ Defines a charfield which automatically converts all inputs to lowercase and saves. """ def pre_save(self, model_instance, add): ...