8đź‘Ť
Short answer is you’ll need to setup a proper webserver on your development machine. Use whichever one (Apache, nginx, cherokee etc) you’re most familiar with.
Longer answer is that the django development server (manage.py runserver
) isn’t designed to do SSL etc and the effort to make it do so is likely greater than you’d want to spend.
See discussions of this passim on the django-users list: http://groups.google.com/group/django-users/browse_thread/thread/9164126f70cebcbc/f4050f6c82fe1423?lnk=gst&q=ssl+development+server#f4050f6c82fe1423
77đź‘Ť
Not to necro a thread, but I found this tool to be extremely easy to use.
It’s a premade django application with very simple install instructions.
You can add a certified key once it is installed simply by running:
python manage.py runsslserver --certificate /path/to/certificate.crt --key /path/to/key.key
I hope this helps any passer-by who might see this.
- [Django]-405 "Method POST is not allowed" in Django REST framework
- [Django]-Unresolved attribute reference 'objects' for class '' in PyCharm
- [Django]-Django REST Framework CSRF Failed: CSRF cookie not set
23đź‘Ť
With django-extensions
you can run the following command:
python manage.py runserver_plus --cert certname
It will generate a (self-signed) certificate automatically if it doesn’t exist. Almost too simple.
You just need to install the following dependencies:
pip install django-extensions
pip install Werkzeug
pip install pyOpenSSL
Now, as Ryan Pergent pointed out in the comments, you lastly only need to add 'django_extensions',
to your INSTALLED_APPS
and should be good to go.
I used a tunnel before, which worked, but this is much easier and comes with many other commands.
- [Django]-Django Admin: how to display fields from two different models in same view?
- [Django]-Celery – Tasks that need to run in priority
- [Django]-Where's my JSON data in my incoming Django request?
7đź‘Ť
Workaround to run https on django.
This can be done with stunnel that lets the Facebook server and stunnel on your machine communicate in SSL and stunnel turns around to communicate with Python in HTTP. First install stunnel. For instance in Mac OS X:
brew install stunnel
Then you need to create a settings file for stunnel to execute. You can create a text file anywhere. For instance, you can create dev_https and input:
pid=
cert=/usr/local/etc/stunnel/stunnel.pem
foreground=yes
debug=7
[https]
accept=8001
connect=8002
TIMEOUTclose=1
stunnel creates a fake certificate. By default on Mac, it’s at /usr/local/etc/stunnel/stunnel.pem. It’ll bring up a warning on your browser saying that your webpage can be fake but Facebook operations still work right. Since stunnel has to listen on one port and Python’s development server cannot run on the same server, you must use different ports for accept (incoming) and connect (internal). Once you have your dev_https file or whatever you called it, run
sudo stunnel dev_https
to start the tunnelling. Then start your Python server.
HTTPS=1 python manage.py runserver 0.0.0.0:8002
Environment variable HTTPS must be set to 1 for it to return secure responses and since we previously set the internal port to 8002, we listen on 8002 from all incoming IPs. Then, your IP:8001 can accept HTTPS connections without changing your webserver and you can continue running another instance of HTTP Python server on a different port.
ref:
https://medium.com/xster-tech/django-development-server-with-https-103b2ceef893
- [Django]-WSGI vs uWSGi with Nginx
- [Django]-How to server HTTP/2 Protocol with django
- [Django]-Multiple pages using Reportlab – Django
6đź‘Ť
I understand this has already been answered, but for a clearer solution:
Step 1: Install library
pip install django-sslserver
Step 2: Add to installed apps in settings.py
INSTALLED_APPS = [
'sslserver',
'...'
]
Step 3: Run the code using runsslserver instead of runserver. Certificate & key are optional.
python manage.py runsslserver --certificate /path/to/certificate.crt --key /path/to/key.key
- [Django]-Django: does the ORM support the SQL "IN" operator?
- [Django]-How to set or get a cookie value in django
- [Django]-Django – SQL bulk get_or_create possible?
4đź‘Ť
This doesn’t solve the automatic testing issue via
./manage.py test
but to run a server with HTTPS you can use RunServerPlus: http://pythonhosted.org/django-extensions/runserver_plus.html
Just install django-extensions and pyOpenSSL:
pip install django-extensions pyOpenSSL
and then run:
python manage.py runserver_plus –cert cert
- [Django]-Dynamic choices field in Django Models
- [Django]-How can I change the default Django date template format?
- [Django]-Django Footer and header on each page with {% extends }
1đź‘Ť
I’ve been able to setup ssl on django’s test server by using stunnel. Here is some info on how to set it up
Just a note, I wasn’t able to get it working using the package provided by debian in apt-get and I had to install from source. In case you have to do the same, please check out the excellent instructions debian forums on how to build debian packages.
There are plenty of instructions online and also on stunnel FAQ on how to create your pem certificate, but ultimately dpkg-buildpackage on Debian built it for me.
I would imagine that things could actually be more straight forward on Windows.
I then was able to make pydev in eclipse start the test server (and also attach to it) by adding a HTTPS=1 environment variable under “Debug Configurations” -> “Environment” -> Variables
- [Django]-How to automatically destroy django test database
- [Django]-Django can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))
- [Django]-Django: When to use QuerySet none()
0đź‘Ť
I got the same problem when wanna test Sign up using Facebook. After use django SSL Server from https://github.com/teddziuba/django-sslserver. This problem is solved. You may need it too.
- [Django]-How to add new languages into Django? My language "Uyghur" or "Uighur" is not supported in Django
- [Django]-Returning pure Django form errors in JSON
- [Django]-Using Basic HTTP access authentication in Django testing framework
0đź‘Ť
This discussion page is really old, earlier Django does not supported SSL, it needs to be done through stunnel or Werkzeug.
Django now supports SSL configuration with django-sslserver:
https://djangopackages.org/packages/p/django-sslserver/
Add in install app and pass certs in command line.
- [Django]-Error: Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>
- [Django]-DatabaseError: value too long for type character varying(100)
- [Django]-Django sending email