I've just started using Django and one thing I find that I'm doing is starting a lot of new projects. I'm finding this process to be pretty tedious every time, even using manage.py startproject *
I'm constantly changing settings in settings.py like media_root and template paths. Just a little background, I come from PHP and CodeIgniter. I never used a stock CI directory. I modified it to meet my needs for a new project. When I needed a new project, I would just copy that directory. manage.py
seems to generate the files on the fly so this approach doesn't seem that possible. Does anyone else have any advice on this?
-
I'm working in Codeigniter learning Django, really hating Codeigniter now I've used Django.– BenbobCommented Dec 15, 2010 at 2:42
-
After translating CI's MVC implementation to how Django does things, it began to really click. I just hate the bare bones stock project that manage.py spits out. There are a lot of settings I find I'm setting over and over again with each new project.– KyleeCommented Dec 15, 2010 at 2:46
-
CI really encourages the fat controller (remember Thomas the tank). You tend to stuff form validation, image resizing and all the other junk into the controller because the models are not really designed for it. Then the libraries are buggy and never updated much, the community isn't very active at all.– BenbobCommented Dec 15, 2010 at 2:52
3 Answers
Lincoln loop has some best practices, they suggest importing settings from a different file. http://lincolnloop.com/django-best-practices/projects/modules/settings.html
Also checkout pip requirements, you might be able to use this to install the settings module from an external source like a git repo.
-
It states machine specific settings and I would need to add that every time to my settings.py file. I was hoping not to have to modify the stock files everytime. Is this unavoidable with Django? Ideally, I'd like to create a template project, modify the files in there, create my directory structure and then just copy that template project folder for new projects. Does anyone else do this?– KyleeCommented Dec 15, 2010 at 3:38
-
The simplest way might be a repository that you import instead of using startproject.– BenbobCommented Dec 15, 2010 at 5:02
-
I don't use any form of source control right now. If I'm understanding you correctly though, I could take a stock project folder, modify the settings and replicate that for each project I need? I didn't know if django-admin.py startproject did more than just create files. If I can do that, that would be ideal.– KyleeCommented Dec 15, 2010 at 21:16
I'm using Paver to automate my Django project setup.
I have a Bitbucket repository with my own bootstrap setup. Eventually I'll make this generic, but for now it might give you some example code
-
I don't want to sound like an idiot but that code didn't make sense to me. The fact that I don't use virtualenv might have something to do with that.– KyleeCommented Dec 15, 2010 at 4:21
-
virtualenv will help you later on when you're developing projects for distribution. In general, it allows you to keep the libraries you are using for a specific project separate from the main python path includes. That really helps dependency management when you go to launch on a different environment. Commented Jan 2, 2011 at 1:03
Sounds like you're starting new projects very often. I assume that's because you're learning. Sure, if there's a custom settings.py
that will save you some typing as you generate your learning projects, create it and use it. You could make your template the whole project directory, but since you're unlikely to have a lot of project-level boilerplate outside of settings.py
, just focus on that one file. The settings file is the essence of the project.
Django development is all about apps. As you learn more, apps will start to become your focus. My advice would be not to pour too much energy into making an efficient assembly line for project creation.
Also, please learn and use use version control. For bonus points, also learn and use virtualenv :)