Django: PyCharm创建Django项目的路径问题
PyCharm通过菜单直接新建Django项目,项目的文件目录结构如下:
djangoProject ├── djangoProject │ ├── asgi.py │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py └── templates
如果是通过PyCharm新建纯Python项目,然后在项目目录下通过django-admin startproject projectname
新建Django项目:
(venv) ubuntu@ubuntu:~/pythonProject$ django-admin startproject djangoProject
则Django项目的目录结构如下,多出一层djangoProject目录:
pythonProject └── djangoProject ├── manage.py └── djangoProject ├── asgi.py ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py
如要和PyCharm直接新建Django项目的目录结构一致,只需要在通过django-admin
新建Django项目时指定路径即可:
(venv) ubuntu@ubuntu:~/pythonProject$ django-admin startproject djangoProject ./
Django项目的目录结构如下:
pythonProject ├── manage.py └── djangoProject ├── asgi.py ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py
附 django-admin startproject
命令的语法及选项:
usage: django-admin startproject [-h] [--template TEMPLATE] [--extension EXTENSIONS] [--name FILES] [--exclude [EXCLUDE]] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color] name [directory] Creates a Django project directory structure for the given project name in the current directory or optionally in the given directory. positional arguments: name Name of the application or project. directory Optional destination directory options: -h, --help show this help message and exit --template TEMPLATE The path or URL to load the template from. --extension EXTENSIONS, -e EXTENSIONS The file extension(s) to render (default: "py"). Separate multiple extensions with commas, or use -e multiple times. --name FILES, -n FILES The file name(s) to render. Separate multiple file names with commas, or use -n multiple times. --exclude [EXCLUDE], -x [EXCLUDE] The directory name(s) to exclude, in addition to .git and __pycache__. Can be used multiple times. --version Show program's version number and exit. -v {0,1,2,3}, --verbosity {0,1,2,3} Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output --settings SETTINGS The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used. --pythonpath PYTHONPATH A directory to add to the Python path, e.g. "/home/djangoprojects/myproject". --traceback Raise on CommandError exceptions. --no-color Don't colorize the command output. --force-color Force colorization of the command output.