Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: the role of the project name

Tags:

django

I am thinking of stating a new Django project and I have to choose a project name now, so I can type:

djangoadmin startproject <something>

This raises doubts, I'm not sure of the name, and I think that I might want to change it in the future. So, I have two questions:

  • What role does project name play in the project code and deployment?
  • What steps do I need to take to change my project's name?

Thank you!

like image 624
Silver Light Avatar asked Mar 23 '11 15:03

Silver Light


People also ask

What should I name my Django project?

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged. So, 1 and 3 are both valid, but 3 would be the recommended approach.

What is project and app in Django?

A project refers to the entire application and all its parts. An app refers to a submodule of the project. It's self-sufficient and not intertwined with the other apps in the project such that, in theory, you could pick it up and plop it down into another project without any modification.

How do I organize my Django project?

The way I like to organize my Django Project is – Keeps all Django apps in apps folder, static files (scripts, js, CSS) in the static folder, HTML files in templates folder and images and media content in the media folder.


2 Answers

Main project name is used as a base for your namespace.

By default, you will have in settings.py line: "ROOT_URLCONF = 'something.urls'".

To change a project name, you need to change every single import that is referring to it.

Of course you can always use modules without 'something' prefix, then you must ensure that there will be no name/namespace conflict between modules. I'm using this option, because I can have same code in a few copies without additional hassle.

like image 52
Jerzyk Avatar answered Oct 22 '22 14:10

Jerzyk


Late to this party, but for future reference this may help somebody. I've just had to change a project name because it clashed with the name of a third-part app. It's easier to change a project name than an app name! (Django 1.11)

Folder structure

project/
    manage.py
    project/
         settings.py
         urls.py
         wsgi.py
    venv/
  1. If using a virtual environment in venv, generate an up to date requirements.txt with pip freeze
  2. Rename both project/ folders to newproject
  3. Change project to newproject in the python files:

manage.py, look for DJANGO_SETTINGS_MODULE

settings.py, look for DJANGO_SETTINGS_MODULE and WSGI_APPLICATION, and a comment. You can and should leave the name of the database and the database user unchanged, assuming you want to keep the data.

urls.py, in a triple-quoted string

wsgi.py, DJANGO_SETTINGS_MODULE plus a comment

  1. If using a virtual environment, you need to recreate it. I renamed venv to old.venv, then virtualenv-3 venv, then use pip install and the requirements file you generated at 1. Trash old.venv when sure the new one is working AOK.

  2. /path/to/project will also feature in system config files such as /etc/nginx and a .service file for gunicorn, which will need changing to /path/to/newproject.

  3. Restart the server and test. Should be working.

Now you can add an app called project to your INSTALLED_APPS!

I now know that it's a good idea to call in-house Django projects ${my_org_name}_something, or similar, so they won't clash with third-party apps.

like image 36
nigel222 Avatar answered Oct 22 '22 13:10

nigel222