Django community: Django Q&A RSS

This page, updated regularly, aggregates Django Q&A from the Django community.

Python 3 Is there anything that prints the order of a class's method calls?

Posted on April 20, 2014 at 3:49 PM by Stack Overflow RSS

Yes, I can manually add a line of print("call xxx") to the start of the definition code of each method. But this seems a little silly. For example: class Test(): def a(self): return self.b() def b(self): return self.c() def c(self): return And when you process Test with something X, and then you call Test().a(), the console will print something like: call -> a call -> b call -> c So you can see how method a calls other mothods, this is helpful for understanding the logic of some complicated Classes (such as Django's ListView) At first, I use metaclass to make X, that is: import functools def print_info(func): @functools.wraps(func) def magic(*args,**kwargs): print('call -> %s'%func.__name__) return func(*args,**kwargs) return magic class BlackMeta(type): def __new__(cls, name, parents, attrs): new_attrs={} for k,v in attrs.items(): if callable(v): new_attrs[k] = print_info(v) else: new_attrs[k] = v return type.__new__(cls, name, parents, new_attrs) class Test(metaclass=BlackMeta): def a(self): return self.b() def b(self): return self.c() def c(self): return it works. But when I add BlackMeta to a subclass of DetailView, and call method get, error raised: So I give up and come here for help. Not necessarily a metaclass, anything that can show me the method call order is OK. Thanks.

Read this post in context »

Where does django output csv file?

Posted on April 20, 2014 at 3:30 PM by Stack Overflow RSS

I'm new to Django and new to web programming in general. I'm trying to export my data in the database into csv file. I've tried "Using the python csv library" in this link : import csv from django.http import HttpResponse def some_view(request): # Create the HttpResponse object with the appropriate CSV header. response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="somefilename.csv"' writer = csv.writer(response) writer.writerow(['First row', 'Foo', 'Bar', 'Baz']) writer.writerow(['Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"]) return response Where can I find the somefilename.csv file? I want it to be in my application folder. So, tt returns HttpResponse object. Do I need to do something with it to get the csv?

Read this post in context »

(Django) Passing 'context' (basic info) to every page, even forms?

Posted on April 20, 2014 at 3:27 PM by Stack Overflow RSS

I'm fairly new to Django (using 1.6.2) and I fear that I may be getting into poor practices, so I must ask: Currently I'm handling some simple views: home, profile. For both of these views, I check if a user is logged in with request.user. And if that user is logged in, I pass his info into context{} and send that to the template. So, do I basically need to do that for every view in which I want to include that information? def home(request): ....etc.... context = { 'players' : players, 'teams' : teams, } if request.user.is_authenticated(): p = Player.objects.get(user=request.user) if p: context['p'] = p return render(request, 'home.html', context) So I basically check if I should ADD that bit of info to the context if it's available before sending it. Problem is, this info is really used as a header, that should be on every page. Is there a way for me to include it on every view without bringing it through context? Many thanks in advance. You guys here at StackOverflow have truly helped so many of us get started!

Read this post in context »

Django order_by after distinct(). Or distinct?

Posted on April 20, 2014 at 3:12 PM by Stack Overflow RSS

I need something like user_messages = UserMessage.objects.filter(Q(from_user=user) | Q(to_user=user)).order_by('dialog_id').distinct('dialog_id').order_by('created') Of course, it doesn't work. I found that I should use annotate(), but it seems to be quiet difficult for me, I'm new to Django. Can you help me?

Read this post in context »

Django: Using views to abstract the logic from template tags?

Posted on April 20, 2014 at 2:26 PM by Stack Overflow RSS

I've written a templatetag that includes much of the logic that I would normally expect to find in a view. While writing some unit tests I started wondering about a slightly different approach. I don't feel experienced enough to judge the pros and cons (maybe this is even a well known practice that I don't know of – or a no go...). That's why I am interested in your opinion. My idea was to write a view to handle all the logic and to use the templatetag as a wrapper that passes all relevant context to that view and returns the rendered HTML. Advantages that I would hope to get from this approach would be easier to provide different output formats easier DRY easier testing nice approach towards ajax and/or edge side includes higher flexibility For example, a templatetag that renders a tree navigation could deliver HTML when accessed through the templatetag and at the same time be accessible through a URL, providing different output formats like JSON, RSS, XML,... Most of the advanced logic could be tested through the view, leaving responsibility for the templatetag tests-cases just to ensure the very basics. Any opinions, hints or links to packages ...

Read this post in context »

Apache and sharing media in a separate directory

Posted on April 20, 2014 at 2:17 PM by Stack Overflow RSS

I am building a django app that runs out of my /Users/me/Dropbox directory. Localhost is pointed at my /Users/me/Sites directory. mod_wsgi installed. apache installed django installed and app working fine in development mode I am trying to embed media in a template This media comes from a directory outside of the django app - in the root of the machine - /PROYECTOS The permissions for the directories and preceding directories are readable by _www I think that I understand that mod_wsgi will serve the dynamic files apache will serve the static files like the css and template files, as well as the media files I am referencing in the /PROYECTOS directory I have the following in my STATICFILES_DIRS = (os.path.join(BASE, "static"), ) STATIC_URL = "/static/" MEDIA_URL = "/PROYECTOS/" WSGI_APPLICATION = 'mbrain.wsgi.application' In the /etc/apache2/extra/vhosts/localhost.conf I have: <VirtualHost *:80> DocumentRoot "/Users/me/Sites/localhost" ServerName localhost WSGIDaemonProcess localhost python-path=/Users/me/Dropbox/mBrain_Adam/mbrain/:/Users/me/Dropbox/mBrain_Adam/mbrain/venv/include/python2.7 WSGIProcessGroup localhost Alias /proyectos/ /PROYECTOS/ <Directory /PROYECTOS> Require all granted </Directory> WSGIScriptAlias / /Users/me/Dropbox/mBrain_Adam/mbrain/mbrain/ <Directory /Users/me/Dropbox/mBrain_Adam/mbrain/mbrain> <Files> Require all granted </Files> </Directory> So to embed a media file in a template I have this as the url: {{ MEDIA_URL }}{{ asset.assetPath }} When I load the page in a browser the console shows ...

Read this post in context »

Reskinning the django admin

Posted on April 20, 2014 at 2:02 PM by Stack Overflow RSS

I want to reskin the django admin. As far as I know just the html and css, I should be able to keep the admin functionality and extend/override/etc. in projects where necessary. I've seen other projects that do this, and their idea seems to be to override every single admin template in their own app and bring it in through the INSTALLED_APPS setting, so this is the approach I have started with and it seems to be working fine. But I worry that it's potentially going to turn into a maintenance nightmare if in future versions of Django things like the admin template tags/etc. suddenly change and stop working, or if the admin gets a major revamp at some point, or even just incremental updates I'd like to incorporate. So my question is: Can I do this without overriding all the templates? Or if not, now that we can have multiple admin sites, can I have one admin instance that uses the stock django templates, and one that uses the ones I'm overriding, just in case something breaks?

Read this post in context »

set_all to get value from custom model manager in django

Posted on April 20, 2014 at 12:25 PM by Stack Overflow RSS

I have two models: Tutorial --> consist of published manager which returns queryset when is_published=True Category In template, I am passing Category object. {% for category in categories %} {% for tutorial in category.tutorial_set.all %} {{ tutorial.title }} {% endfor %} {% endfor %} Instead of getting all, I want to get from published manager like: Tutorials.published.all() How to achieve this?

Read this post in context »

'bootstrap_tags' is not a valid tag library

Posted on April 20, 2014 at 11:24 AM by Stack Overflow RSS

Im using pinax-theme-bootstrap-account with django-user-accounts when I want to use pinax templates i get this error : 'bootstrap_tags' is not a valid tag library: Template library bootstrap_tags not found,tried django.templatetags.bootstrap_tags,django.contrib.admin.templatetags.bootstrap_tags,django.contrib.staticfiles.templatetags.bootstrap_tags,account.templatetags.bootstrap_tags here is pinax-theme for signup.html {% extends "site_base.html" %} {% load url from future %} {% load i18n %} {% load bootstrap_tags %} {% block head_title %}{% trans "Sign up" %}{% endblock %} {% block body %} <div class="row"> <div class="span8"> <form id="signup_form" method="post" action="{% url "account_signup" %}" autocapitalize="off" class="form-horizontal"{% if form.is_multipart %} enctype="multipart/form-data"{% endif %}> <legend>{% trans "Sign up" %}</legend> <fieldset> {% csrf_token %} {{ form|as_bootstrap }} {% if redirect_field_value %} <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" /> {% endif %} <div class="form-actions"> <button type="submit" class="btn btn-primary">{% trans "Sign up" %}</button> </div> </fieldset> </form> </div> <div class="span4"> {% include "account/_signup_sidebar.html" %} </div> </div> {% endblock %}

Read this post in context »

Django: reverse for REST framework login route not working

Posted on April 20, 2014 at 11:05 AM by Stack Overflow RSS

I am pretty new to Django. Now I try to using Django Rest Framework. I have my custom login template, and I want to POST my login form to the Rest Framework's login route ('/api-auth/login' by default). In my main I have: url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) So, in my template I'm trying to fetch url by namespace ('rest_framework') and name ('login'): <form id="loginForm" method="POST" action="{% url 'rest_framework:login' as login_url %}" name="loginForm"> But as a result I have empty action attribute in my form. Can someone explain me, what I'm doing wrong?

Read this post in context »

Weird UnicodeDecodeError when POSTing in Tastypie

Posted on April 20, 2014 at 10:49 AM by Stack Overflow RSS

I know what is a UnicodeDecodeError but I really don't understand why it occurs in my case : class ScanEventResource(ModelResource): scanned_card = fields.ForeignKey(CardInfoResource, 'scanned_card') scanned_at_owner = fields.ForeignKey(BusinessInfoResource, 'scanned_at_owner') class Meta(CommonResourceMeta): queryset = ScanEvent.objects.all() resource_name = 'scanevents' fields = [] list_allowed_methods = ['post'] When I try a POST request with a payload like: {"scanned_card": '/api/v1/card_infos/3', "scanned_at_owner": '/api/v1/business_infos/1'} Most of the time I get a HTTP 500 with a UnicodeDecodeError : 'ascii' codec can't decode byte 0xc3 in position 99 In one particular case (when id scanned_card equals 2) that works (HTTP 201). I think you can not guess the problem without other parts of the code, but I don't know what to show since I really don't understand why this error occurs. Ask me to add some code if needed. Thanks for your help.

Read this post in context »

how to combine tables?

Posted on April 20, 2014 at 9:56 AM by Stack Overflow RSS

please help make the ability to dynamically select status. I have a model: class UserProfile(models.Model): CHOICES_status = ( ('0', 'none'), ('1', 'status1'), ('2', 'status2'), ('3', 'status3'), ('4', 'status4'), ) user = models.OneToOneField(User) family = models.CharField(max_length=30, blank=True) name = models.CharField(max_length=30, blank=True) nation = models.CharField(max_length=30) status = models.CharField(max_length=30, blank=True, choices=CHOICES_status, default='0') avatar = models.ImageField(upload_to='userprofile/', blank=True) nation_show = models.BooleanField(default=True, blank=True) it has a fixed set of statuses. creating a user selects a certain status. I put a set of statuses in a separate table: class UserStatus(models.Model): status = models.CharField(max_length=30) Now I need to do so variable CHOICES_status generated dynamically based on the model UserStatus

Read this post in context »

To retrieve data from django database and display in table

Posted on April 20, 2014 at 9:51 AM by Stack Overflow RSS

I am trying to retrieve data from db in django. I want to display it in a table. I am getting an error as:\ coercing to Unicode: need string or buffer, TransType found There are two models in my file: class TransType(models.Model): name = models.TextField() created = models.DateTimeField(auto_now_add = True) updated = models.DateTimeField(auto_now = True) def __unicode__(self): return class Trans(models.Model): transtype = models.ForeignKey(TransType) script = models.CharField(max_length=200) created = models.DateTimeField(auto_now_add = True) updated = models.DateTimeField(auto_now = True) class Meta: unique_together = (("transtype", "script"),) def __unicode__(self): return self.transtype My file def updatetrans(request): json_data=open('/home/ttt/Ali/a.json').read() data = json.loads(json_data) for pk, pv in data.iteritems(): for k,v in pv.iteritems(): try: trans_type = TransType.objects.get_or_create(name=k) trans = Trans() trans.transtype_id = trans_type[0].id if isinstance(pv[k], basestring): script = pv[k] else: print "****** List ****" script = pv[k][1] trans.script = script print " Inserted ==>", script except Exception, e: print e #print "Not inserted ==>", pv[k][1] pass #return HttpResponse("Done") info = TransType.objects.all() info2 = Trans.objects.all() bookdata = { "details" : info, "details" : info2 } print bookdata return render_to_response("account/updatetrans.html", bookdata, context_instance=Context(request)) My file url(r'^updatetrans/$', 'booki.account.views.updatetrans', name='updatetrans'), My updatetrans.html file {% load i18n %} <!doctype html> <html> <body> <table border="1" style="width:800px"> {% for script in detail %} ...

Read this post in context »

celery error : TypeError: unhashable type: 'list'

Posted on April 20, 2014 at 9:32 AM by Stack Overflow RSS

I'm trying to make celery work on my django project. But when I try to call a task with delay or apply_async, I get the following exception : x.delay(3,9) Traceback (most recent call last): File "", line 1, in File "/Users/jibaku/envs/85mm/lib/python2.7/site-packages/celery/app/", line 453, in delay return self.apply_async(args, kwargs) File "/Users/jibaku/envs/85mm/lib/python2.7/site-packages/celery/app/", line 555, in apply_async **dict(self._get_exec_options(), **options) File "/Users/jibaku/envs/85mm/lib/python2.7/site-packages/celery/app/", line 351, in send_task reply_to=reply_to or self.oid, **options File "/Users/jibaku/envs/85mm/lib/python2.7/site-packages/celery/app/", line 305, in publish_task **kwargs File "/Users/jibaku/envs/85mm/lib/python2.7/site-packages/kombu/", line 161, in publish compression, headers) File "/Users/jibaku/envs/85mm/lib/python2.7/site-packages/kombu/", line 237, in _prepare body) = dumps(body, serializer=serializer) File "/Users/jibaku/envs/85mm/lib/python2.7/site-packages/kombu/", line 137, in dumps if serializer and not self._encoders.get(serializer): TypeError: unhashable type: 'list' And the x function is really basic : from __future__ import absolute_import from celery import shared_task @shared_task def x(x, y): return x + y Does anyone has ever encounter a similar error ? (I can't find people that encountered the same error with google)

Read this post in context »

Error when converting ui. file to py. file

Posted on April 20, 2014 at 9:06 AM by Stack Overflow RSS

I'm using windows 8 64bit and python 2.7. I have downloaded and installed WinPython( and desgined a GUI in QT designer. I know that I'm supposed to convert ui to py using pyuic4, but when I write this command in cmd(in the ui's path) : pyuic4 -x GUI.ui -o I get this error : Traceback (most recent call last): File "C:\Python27\Lib\site-packages\PyQt4\uic\", line 31, in <module> from PyQt4 import QtCore ImportError: DLL load failed: %1 is not a valid Win32 application. Any idea what to do ? Thank you!

Read this post in context »

Multiple aggregations on date ranges in Django

Posted on April 20, 2014 at 6:19 AM by Stack Overflow RSS

............Models............ class Product(models.Model): user = models.ForeignKey(User) name = models.CharField(max_length=140) description = tinymce_models.HTMLField() class Purchase(models.Model): user = models.ForeignKey(User, blank=True, null=True) product = models.ForeignKey(Product) sale_date = models.DateTimeField(auto_now_add=True) price = models.DecimalField(max_digits=6, decimal_places=2) I am looking to get an output that says the sum of the purchase prices for a product in the past month and the past week, but want to do this for multiple products. The output would look something like this that i could loop through in my templates... product1 name-- product1 description -- sum of product1 weekly sales -- sum of product1 monthly sales product2 name-- product2 description -- sum of product2 weekly sales -- sum of product2 monthly sales Should I used raw sql? What would that query look like? Should i try to use sqlalchemy or can i do this in the Django ORM?

Read this post in context »

Django: Most Efficient Way To Filter A Queryset Repeatedly

Posted on April 20, 2014 at 5:38 AM by Stack Overflow RSS

I have a model that looks something like this: class Item(models.Model): name = models.CharField() type = models.CharField() tags = models.models.ManyToManyField(Tags) In order to render a given view, I have a view that presents a list of Items based on type. So in my view, there's a query like: items = Item.objects.filter(type='type_a') So that's easy and straight forward. Now I have an additional requirement for the view. In order to fulfill that requirement, I need to build a dictionary that relates Tags to Items. So the output i am looking for would be something like: { 'tag1': [item1, item2, item5], 'tag2': [item1, item4], 'tag3': [item3, item5] } What would be the most efficient way to do this? Is there any way to do this without going to the database with a new query for each tag?

Read this post in context »

ajax appended list-group-item's do not trigger click events

Posted on April 20, 2014 at 5:28 AM by Stack Overflow RSS

I have an accordion that is populated via Django Template tags. In side each accordion item i have a list-group. The list-group' items are populated on DomReady via ajax. This works great. However, I need the list-group-items to be able to trigger another ajax call so I can query the database and render the list-group-item's related objects in another div. If i hard code an item it works fine, but the ajax created ones do not trigger an event. Any help is greatly appreciated. Thank you very much. Ajax/Html: <div class="panel-group" id="accordion"> {%for fabCatagory in fab_categories%} <div class="panel panel-primary"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion" data-target="# {{fabCatagory.categoryId}}" id="{{fabCatagory.categoryId}}btn"> {{fabCatagory}} </a> </h4> <script type="text/javascript"> $(document).ready(function(){ $.ajax({ dataType: 'json', type: 'GET', url: '/companion/topic/{{fabCatagory}}/', success: function(result){ for(var i=0; i < result.topics.length; i++){ $("#{{fabCatagory.categoryId}}topics").append( "<a id='"+result.topics[i].topicId+"' class='list-group-item' ><li>"+result.topics[i].topic+"</li></a>" );//end append }//end for },//end success });//end Ajax });//end </script> </div> <div id="{{fabCatagory.categoryId}}" class="panel-collapse collapse"> <div class="panel-body"> <div id="{{fabCatagory.categoryId}}topics" class="list-group"> <!--Ajax Data Goes Here--> </div> </div> </div> </div> </div> <script type="text/javascript"> var topicLinkId = $(".list-group").attr('id); $("#"+topicLinkId).on('click', function(){ //This doesn't work console.log('success');//this will be replaced, ajax function }) ; </script> {%endfor%} </div>

Read this post in context »

django celery get() for getting the result form task

Posted on April 20, 2014 at 2:35 AM by Stack Overflow RSS

I have an API call to the server where I am doing some processing using celery. The output from the celery is passed back to client. I used som = task_async_get_cached_session.delay('session_123') print 'before' result = som.get(timeout=1) print 'after' I looked at the celery -l INFO and the task get succeeded in succeeded in 0.024465521s: {data: {session_123: something}} But my client was not get response back and and I put timeout and now I am getting The operation timed out. (<class 'celery.exceptions.TimeoutError'>) When I looked at the logs trace, only before is printed. My question how to use celery without get() when you want the result generated from the celery task to the client? I know that get() will convert my API call to synchronous, but what alternate I have ? What is the real use of celery ? Is there any other way to change my API to behave Asynchronous?

Read this post in context »

ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings

Posted on April 20, 2014 at 2:26 AM by Stack Overflow RSS

I know this has been asked before, but all the ones that I can find did not help. I'm hoping someone can look at my settings and tell me what I'm doing wrong (and help others in the future that are struggling as much as me!!) This is the error message in complete: DocumentRoot: '/var/www/html' URI: '/mysite' Location: '/mysite' Directory: None Filename: '/var/www/html/mysite' PathInfo: '' Phase: 'PythonHandler' Handler: 'django.core.handlers.modpython' Traceback (most recent call last): File "/usr/lib64/python2.6/site-packages/mod_python/", line 1540, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "/usr/lib64/python2.6/site-packages/mod_python/", line 1232, in _process_target result = _execute_target(config, req, object, arg) File "/usr/lib64/python2.6/site-packages/mod_python/", line 1131, in _execute_target result = object(arg) File "/usr/lib/python2.6/site-packages/django/core/handlers/", line 212, in handler return ModPythonHandler()(req) File "/usr/lib/python2.6/site-packages/django/core/handlers/", line 174, in call self.load_middleware() File "/usr/lib/python2.6/site-packages/django/core/handlers/", line 39, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File "/usr/lib/python2.6/site-packages/django/utils/", line 276, in getattr self._setup() File "/usr/lib/python2.6/site-packages/django/conf/", line 42, in _setup self._wrapped = Settings(settings_module) File "/usr/lib/python2.6/site-packages/django/conf/", line 89, in init raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e)) ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings My http.conf is as follows: VirtualHost ommitted:80 ServerAdmin ommitted ServerName ommitted <Location "/mysite"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE mysite.settings PythonOption ...

Read this post in context »

Django/python: Understanding paths with os.path.join

Posted on April 20, 2014 at 2:12 AM by Stack Overflow RSS

As I was looking through my file in my current project, I realized I wasn't too sure what was really going on under the hood with python in terms of os.path.join I tried looking it up, but its a bit confusing - and seems a bit esoteric when you delve deep. So lets take the following example: os.path.join(PROJECT_DIR, 'templates'), Some points I'd like answered from this example: What exactly is os.path.join doing here? What exactly is being joined? What is PROJECT_DIR? Where was PROJECT_DIR set and how does PROJECT_DIR itself point to the project directory all the time, regardless of its location(on a server, locally, etc)? Now lets consider this example (which I took from my friend), that makes it the case that when I run on a server(ON_OPENSHIFT seems to be my host) I use a particular static directory: if ON_OPENSHIFT: STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) else: STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, ...

Read this post in context »

Dynamically limiting Inline Model Fields shown in Django admin

Posted on April 20, 2014 at 1:55 AM by Stack Overflow RSS

I'm trying to exclude certain fields ('item_1', 'item_2') from being shown from my model based on the value of another field ('configuration'). The model is featured as an inline in the Django admin. I've tried the code below but nothing changes in the admin. The detection of the value of 'configuration' seems to work but not the exclusion. As a side note I'm using the Django Suit admin skin. Any help much appreciated. Thank you. class LayoutForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(LayoutForm, self).__init__(*args, **kwargs) configuration = self.instance.configuration if configuration == '2d': class Meta: exclude = ['item_1','item_2'] class LayoutInline(SortableTabularInline): model = Layout sortable = 'order' extra = 0 form = LayoutForm class ModuleAdmin(SortableModelAdmin): inlines = [LayoutInline],ModuleAdmin)

Read this post in context »

Django does not work ... sometimes

Posted on April 20, 2014 at 1:13 AM by Stack Overflow RSS

I'm crazy or this very wired: in my model I've one boolean field for "soft" registry deletion. When I mark for deletion [=>True] .. It's updated! BUT... when I try to do the oposite.. does Not work: ## Models class Posts(models.Model): autor = models.CharField(max_length = 30) titulo= models.CharField(max_length = 60) url = models.CharField(max_length = 50) # falta agregar manualmente texto = models.TextField() hidden= models.BooleanField() fecha = models.DateTimeField() ## Views # delete def posts_delete(request, id): try: p = Posts.objects.get(id=id) except Posts.DoesNotExist: raise Http404 if HARD_DELETE: p.delete() else: p.deleted=True p.date_deleted = return HttpResponseRedirect('/posts' + '/list/deleted/' +id) # restore def posts_undelete(request, id): try: p = Posts.objects.get(id=id) except Posts.DoesNotExist: raise Http404 p.deleted=False #p.date_deleted = None return HttpResponseRedirect('/posts' + '/list/undeleted/' +id) ANY idea ? :)

Read this post in context »

Does Google not like Django?

Posted on April 20, 2014 at 12:24 AM by Quora RSS

1 AnswerSee question on Quora

Read this post in context »

How do you access static file with another static file in django?

Posted on April 20, 2014 at 12:16 AM by Stack Overflow RSS

I have an html file served as a static file on my site so that I can load it into a rendered page with ajax, in this static html file, I am trying to put images in it but it won't load them on the page. My directory structure for static files is the base static directory, and then a subfolder for html files, another for images.

Read this post in context »