-1

I'm using Django, and I can't figure out an easy way to keep a development and public version of my Django app other than simply having 2 apps and copying code over for every new public version.

Is there a better way?

Thanks!

5
  • How do development and public versions differ? Only settings or something more? Commented Jul 22, 2014 at 19:04
  • @FrEaKmAn - 2 things for me: In settings, there is something called "DEBUG" which shows detailed errors if enabled, or just a 404/500/whatever screen if not. I don't want it enable for the public version. The development version should also be for when I'm adding new features. But I need a smooth way of moving code to the public version. Commented Jul 22, 2014 at 19:07
  • 2
    Do you use a version control system? If not, use it. Git, SVN, whatever. You'll thank me later. On top of the obvious benefits of a version control system, you can have a production branch and a development branch, and whenever you want to update the production version, just merge the development branch into it. Commented Jul 22, 2014 at 19:18
  • There are numerous topics on this all over the web. Write a common settings file and import other settings files according to the environment. If you're on a production server (check the hostname for example), import a prod.py, or else import a dev.py settings file. One codebase, multiple deployment environments. And yeah, use git if you want staging (this is probably what you want) Commented Jul 22, 2014 at 19:22
  • Btw, how do you run the production version? If the only difference between development/production is the DEBUG setting, it seems to me you're missing insights in some pretty big and important topics. Commented Jul 22, 2014 at 19:28

2 Answers 2

3

You may want to look into the "gitflow" system. There are many variations, you and don't have to use git, but the idea is to use branches for development and production.

http://nvie.com/posts/a-successful-git-branching-model/

Sign up to request clarification or add additional context in comments.

Comments

1

I use vagrant for development with GIT, in order to localy test and then push I use separate settings for both of them. To be more detailed on how I implement it (small group of devs):

  1. Setup virtualenvwrapper (http://virtualenvwrapper.readthedocs.org/en/latest/install.html)
  2. Create a new project (mkproject)
  3. create a settings folder in the same level your settings.py exists (make sure you create a __init__.py file in the folder as well).
  4. Move the settings.py in the settings folder and rename it as dev.py
  5. Copy dev.py and create in the same folder with the name prod.py

When you create dev.py and prod.py include the following lines in the top (actually replace BASE_DIR):

import os
DJANGO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(DJANGO_ROOT)

Those are your dev and prod files, separate databases (for instance you could be using sqlite for local dev), apps and settings based on your environment (for instance dev should have debug toolbar in my environment), additionally you can create a devurls.py file in the root directory of the project and point dev.py to use that file (ROOT_URLCONF setting). When you've created the files, n your virtualenv dir folder under the virtualenv of the working project, there should be a bin/ folder, inside there a postactivate file in that file enter:

export DJANGO_SETTINGS_MODULE="projectname.settings.dev"

Where projectname is your project. This way you have a dev and prod settings file (additionally devurls if you want) with the use of git you can create branches and develop as you wish. Most dev environment won't need anything more than that.

1 Comment

Thanks. I haven't tried it out yet, so I won't accept your answer quite yet, but I'll make sure to. (+1 for actually going through the steps for the not-so-skilled-server-developer-that-develops-for-iOS)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.