django

How to pass a url as a parameter to a handler in Django?

A project I'm currently working on has a sort of proxy functionality where users can browse to another URL through the site. I was hoping the URL could be something like this: www.mydomain.com/browser/[URL here] However I'm having trouble capturing a URL as a parameter like this. I think my inexperience with regex is failing me her...

Customizable Authencation backends not followed by Django's own login testcases. Why ?

I learnt that using Customizable Authencation backends philosophy, one can create a website which accepts email addresses as usernames. But after building the corresponding logic and testing that my code is working fine, I found one issue with Django's own testcases. They were failing to follow the Customizable Authencation backend philo...

How do I access a python list from a django templatetag?

I have created a templatetag that loads a yaml document into a python list. In my template I have {% get_content_set %}, this dumps the raw list data. What I want to be able to do is something like {% for items in get_content_list %} <h2>{{items.title}}</h2> {% endfor %}` ...

In a Django unit test driver how do you test if an email is sent?

In a Django unit test driver how do you test if an email is sent? ...

Filter Django Haystack results like QuerySet?

Is it possible to combine a Django Haystack search with "built-in" QuerySet filter operations, specifically filtering with Q() instances and lookup types not supported by SearchQuerySet? In either order: haystack-searched -> queryset-filtered or queryset-filtered -> haystack-searched Browsing the Django Haystack documentation didn'...

Django Newbie ManyToManyField Template Question

Hello. I have a Django model with a ManyToManyField and I'm trying to iterate the contents of that field in a comma-delimited list in my template. I'm getting some unexpected results. {% for painting in paintings_list %} <p>{% for item in painting.style.all %} {{ item.style|join:', ' }} {% endfor %}</p> {% endfor %} Th...

Running a PHP script inside a Python WSGI enviroment

Hi all, I have a simple PHP script that outputs a dir listing in XML format. I use it to let a flash slideshow know what files are available to show. I've just added the flash to a website that's powered by Django and the PHP file is now served up as it is, not parsed. It's in the directory with the images under my media directory. Th...

Django request.POST does not contain the name of the button that submitted the form

I have a django form with two different submit buttons, on the view where the form is submitted to I need to know what submit button was pressed and take different actions accordingly. From what I have read the submit button's name or id should be somewhere in the request.POST dictionary, but it not there! This is a fragment of my fo...

Django: What is the stack order in Django?

I think that is the right way to ask it. I'm wondering which parts of the code execute first, second, etc. My assumption would be, but I don't know: Request Middleware View Model Middleware Response The reason I'm asking is because I want something to happen dynamicall in the Model based on a request variable and I'm trying to devic...

imports while starting an interactive shell

When I start the interactive django shell through manage.py, by executing python -v manage.py shell from the project directory, I see a lot of modules of format django.package.module getting imported in the verbose output but still I have to import them to use it in the shell. The same happens when I just run the Python shell (with...

Access request in django custom template tags

My code in myapp_extras.py: from django import template register = template.Library() @register.inclusion_tag('new/userinfo.html') def address(): address = request.session['address'] return {'address':address} in 'settings.py': TEMPLATE_CONTEXT_PROCESSORS =( "django.core.context_processors.auth", "django.core.contex...

Readonly fields in the django admin/inline

I use this snippet to show several fields in my admin backend as readonly, but as noticed in the comments, it does not work on stackedinline/tabularinline. Is there any other way to achieve this? I have a list of objects attached to a model and just want to show it in the model's details view without the possibility to change values. ...

JSON python to javascript

I want to transfer some data from python to javascript. I use Django at python side and jQuery at javascript side. The object I serialize at python side is a dictionary. Besides simple objects like lists and variables, this dictionary contains instances of SomeClass. To serialize those instances I extendeded simplejson.JSONEncode like...

Django and Postgres transaction rollback.

I have a piece of code that works in a background process which looks like from django.db import transaction try: <some code> transaction.commit() except Exception, e: print e transaction.rollback() In a test, I break <some_code> with data that causes a database error. The exception is following File "/home/comm...

Django: customize form in template according to field attribute

hi, I've got the Category model and SearchForm form shown below. I'd like to do 2 things in my template: -to separate in the form the Category instances having a given type to be able to apply a specific style to them in my CSS -to show the hierarchy of my category instances Basically I need to access the Category's parent and style ...

How to set timeout for urlfetch in Google App Engine?

I'm trying to have Django (on top of GAE) fetch data from another web service. I'm often hit with error like this: ApplicationError: 2 timed out Request Method: GET Request URL:http://localhost:8080/ Exception Type: DownloadError Exception Value: ApplicationError: 2 timed out Exception Location: /google_...

inserting a form to session raises picklingerror - django

I receive an exception when I add a form to the session: PicklingError: Can't pickle <class 'django.utils.functional.__proxy__'>: attribute lookup django.utils.functional.__proxy__ failed The form includes a few simple fields and has some javascript attached to a widget. It might be that Django forms cannot be pickled at all, but the e...

How can I let a user select from a dropdown OR provide their own value in the Django admin?

I'm using a third-party app (Satchmo) and I want to change a text field to a dropdown with some preset options plus a text field where the user can fill in their own value. I know how to mess with the admin model to change the field to use a dropdown of presets, but not how to preserve the users ability to specify the value themselves. ...

django reusable template code

So as I am architecting my project, I'm thinking I must be doing something wrong. Some pieces of template code are reusable that makes me want to extract the code out of the template, but I can't find a good way. For example, some buttons are the same design all throughout the website. What's the best way to extract it out of the page...

How to create form from two models in Django

I have UserProfile model defined in settings.py. Now I want to create registration form that have fields both from User and UserProfile models. Is there easy way to do it? I'm using uni_form to create nice looking forms if this helps. ...