Django (blog system): Based on Pycharm How to create multiple apps under a Django project

Source: Internet
Author: User

Background: Usually when we create a Django system, in order to divide the business module clearly will often put a separate business module into an app, if multiple independent business modules will create multiple apps, generally in order to better manage these apps, Will store them all in a folder directory (Python package) for apps.

How to create an Apps directory (Python package)

New app

1) Execute the new app command:

To enter the project directory first, CD project_name and then execute the following command (below, the CD Project_Name is not required in the project directory)

python manage.py startapp app_name or Django-admin.py Startapp app_name

Typically, a project has multiple apps, and of course a common app can be used in multiple projects.

Similar to the project name, the app name also needs to be a legitimate Python package name, such as Blog,news, AboutUs, and so on.

2) manually move the app location under the apps package in the File Management window:

The default new app is saved to the root of the project, directly under the Files window cut into the apps file (do not need to pycharm the IDE, so that the path of the template file will automatically follow the change).

To Modify the settings.py configuration file:

1) Configure the app name to Installed_apps:

Installed_apps = [    'Django.contrib.admin',    'Django.contrib.auth',    'Django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'Django.contrib.staticfiles',    'app_name'}

2) Set the file path:

Import OS, sys # Build paths inside the project like This:os.path.join (Base_dir, ...) Base_dir = Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)))#  Add the same as below to specify the location of the folder where the app is located:'apps')print(" Sys.path: " + sys.path. __str__ ())

At this point the actual directory structure of the project is as follows:

How to write a path when templates include between different apps:

For example: Vmaig_blog when the app references a template in Vmaig_auth, it is written as follows:

Django (blog System):

Link: Https://pan.baidu.com/s/1min8tAS Password: NPBQ

Django (blog system): Based on Pycharm How to create multiple apps under a Django project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.