I'm trying to setup a local Django dev environment using VMs enabled with Vagrant but I'm not sure what's the best way to go about it.
I did a git clone
for Django files from production server and installed all the modules that the production server has on my local VM. I wanted to avoid installing a database on my local VM but ran into some problems with the sessions. The local machine is using SESSION_COOKIE_DOMAIN='localhost'
and the production is using SESSION_COOKIE_DOMAIN='.mydomain.com'
so that creates some confusion.
Not to mention that on the setting.py on my dev environment I had to change IPs to point to the public IP address of the database (thus poking a hole on the security) while my production settings.py is using the local IPs so I ended up using different settings.py files.
I can continue experimenting with new methods but I really have to get going with the project and I'm pretty sure some people had this figured out already.
So how did you setup your Django dev environment?
As a result, experienced Python/Django developers typically run Python apps within independent Python virtual environments. This enables multiple different Django environments on a single computer. The Django developer team itself recommends that you use Python virtual environments!
I have a public repo on GitHub available here:
https://github.com/FlipperPA/djangovagrant
Instructions from the README.md:
Django / Python / MySQL
This is a Vagrant project for Django development.
This does not yet support berkshelf or librarian; all necessary repos are included in 'cookbooks'.
Prerequisites, all platforms:
Virtualbox https://www.virtualbox.org/wiki/Downloads Vagrant http://downloads.vagrantup.com/
Pre-requisites, Windows only:
git-bash ruby rvm
Fairly easy to get it running:
vagrant up
vagrant ssh djangovm
** (Note: You are now in the Virtualbox VM as superuser vagrant)
sudo apt-get install python-pip
** (Note: PIP is a Python package manager)
sudo apt-get install python-mysqldb
sudo pip install django
Starting a Django project:
django-admin.py startproject django_project
cd django_project
python manage.py runserver [::]:8000
The VM is configured to use port forwarding. If everything went right, you should be able to access the running server through the browser on your computer running the virtual machine at this url:
http://localhost:8001/
New to Django? Next steps? I highly recommend: http://www.tangowithdjango.com/ For more advanced topics, check out Two Scoops of Django: http://twoscoopspress.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With