Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Pycharm create a Django project

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how Pycharm creates a Django project", with detailed content, clear steps and proper handling of details. I hope this article "how Pycharm creates a Django project" can help you solve your doubts.

Pycharm installs the Django framework

II. Build a new Django project

1. Manage.py is an administrative role with features such as:

(1) create app: python manage.py startapp miaTest, where startapp is the command and miaTest is the name of app

(2) manage the database

Python manage.py sqlall miaTest: view all the tables under the miaTest app

Python manage.py syncdb: synchronizing databases

(3) manage the server

Python manage.py runserver ip:port- > change the ip and port number of access

2 、 Venv

To use django, you first need to establish a virtual work environment in which packages can be installed and isolated from other projects, mainly to solve the version and dependency problems in the process of Python software development, so that each project has its own independent installation directory ring.

3.mySite2

(1) init.py: this file is empty by default. Only by defining this file will the python virtual machine think that the current folder is a legitimate package, representing that the Python program under the directory is part of module. So it's the logo of package.

(2) Settings.py: including app path, database configuration, sql statement, static file directory, middleware, session storage related configuration

(3) Urls.py: the entry of all URLs will be associated with the functions in views

(4) Wsgi.py

4.Templates

It is mainly composed of html code and logic control block code.

Create a WebApp project in the Django project

1. Open the terminal window

2. Enter the command: python manage.py startapp django_web

3. The new directory structure is as follows:

4. Modify the settings.py file and register the project

The development of Django follows the MTV pattern (models, templates, views), views.py is responsible for performing operations, models.py is responsible for data processing (such as database connections), and the template for storing web pages in the templates directory

5. Create a new index.html file under templates

6. Write a views.py file and define the operation to access the index.html file

7. Write a urls.py file that defines the url path to access the index.html (using regular expressions)

4. Run the project: enter the command in the Terminal of pycharm to run the server:

Enter url: http://127.0.0.1:8000/index/ in the browser to see the following page

Add resources (css, image, js) to the project

1. The directory structure is as follows:

2. Modify the index.html as follows:

3. Add the following configuration at the end of the settings.py file

Note: when setting a static file directory for STATICFILES_DIRS, note that the directory you set is a list or tuple, where the values of each tuple or list must be separated by commas. Even after the last value, add a comma.

Read here, this "Pycharm how to create Django project" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report