django
How to install mod_wsgi for apache 2.4 and python 3.4 on windows?
It is better to build mod_wsgi yourself from code rather than use an arbitrary binary off the net. The steps are as follows. Ensure you have a decent Apache installation which includes header files, e.g. Apache 2.4.37 Win64 from Apache Lounge . Preferably installed at location of C:/Apache24. Ensure your Python installation is set up … Read more
What is the best way to store password in database when API call requires sending of password in plain text?
do your users have to log into your website to use it? if you also are making use of a password authentication scheme, you could piggy back on top of that. Use the login password for your site as a cipherkey in a symmetric key cipher to encrypt the api password. then you need only … Read more
Django: dynamic database file
The django.db.connections is a simple wrapper around DATABASES defined in your settings. The wrapper class is here: django.db.utils#L137-L227 from django.db import connections # Add connection information dynamically.. connections.databases[‘new-alias’] = { … } # Ensure the remaining default connection information is defined. # EDIT: this is actually performed for you in the wrapper class __getitem__ # … Read more
Django – forms.FileField() initial value
I’m not sure, if this is what you want, but… Obviously you cannot set initial data for a file input (this would imply that you send a file to the user). Django has a ClearableFileInput widget though, and this widget pretends to show initial data: it displays a link to the uploaded file if the … Read more
Forbidden (403) CSRF verification failed. Request aborted
You need to add {% csrf_token %} in your form https://docs.djangoproject.com/en/2.2/ref/csrf/ like that : <form> {% csrf_token %} <anything_else> </form> Also, you have to use RequestContext(request) everytime you use render_to_response : return render_to_response(“login.html”, {“registration_id”:registration_id}, context_instance=RequestContext(request)) And you have to import authenticate and login : from django.contrib.auth import authenticate, login
Creating Partial Indexes with Django 1.7
Django 2.2 and later As of version 2.2 Django supports declarative partial unique indexes on databases that support them (PostgreSQL and SQLite). So you could do something like: from django.db.models import Model, Q, UniqueConstraint class Post(Model): … class Meta: constraints = [ UniqueConstraint( fields=[“title”, “blog”, “category”], name=”idx1″, condition=Q(category__isnull=False)), UniqueConstraint( fields=[“title”, “blog”], name=”idx2″, condition=Q(category__isnull=True)), ] Django … Read more
Django static files on heroku
Eventually solved this using the below in my urls file – from this question: Heroku – Handling static files in Django app from <app> import settings urlpatterns += patterns(”, (r’^static/(?P<path>.*)$’, ‘django.views.static.serve’, {‘document_root’: settings.STATIC_ROOT}), )
Django/DRF – 405 Method not allowed on DELETE operation
The response looks very similar to that of the list view (/api/resource/) for a ViewSet. List views only support GET, to list all of the objects, and POST to create a new object. DELETE requests are only allowed on the detail view (/api/resource/1/). This is because Django REST Framework needs to know what object you … Read more