python - No content in django HttpResponseBadRequest -


i'm trying organize error messages returned django application, , having problems subclasses of httpresponsebadrequest objects having empty content:

in views.py:

class httpnocontentavailable(django.http.httpresponsebadrequest):     content = "must add content before making request."  def get_content(request, project_id):     project = project.objects.get(pk=project_id)     if not project.has_content():         return httpnocontentavailable()     ... 

it works following:

def get_content(request, project_id):     project = project.objects.get(pk=project_id)     if not project.has_content():         return httpnocontentavailable("must add content before making request.")     ... 

in application, there many views need return same 400 response depending on whether or not there content, , i'd keep response content stored in 1 place. make matters more "interesting," unit tests running on development server pass -- http 400 responses correct content, when running in production http 400 responses no content.

how can http 400 response have correct content? (or, more generally, how suggest organized code accomplish goal of having response content stored once?)

you should override constructor in subclass instead of defining content class variable.

for example:

 def __init__(self):          super(django.http.httpresponsebadrequest, self).__init__("must add content before making request.") 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -