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 to install Django and create projects and applications

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

Share

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

How to install Django and create projects and applications, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

"Django is a very powerful Python-web framework. Today, we will teach you from installing django to creating projects and applications, and enter the django world."

01

-

Create a virtual environment

To create a virtual environment, you must first have installed Python correctly, if not, go to > Python Zero getting started tutorial | install the Python programming environment on different operating systems!

Take Windows operating system as an example:

01. First of all, create a "Django" folder in your favorite hard disk partition, and I'll use D:\ Django as a demonstration here!

02. Go to the Django folder you just created, hold down the keyboard shift key, right-click in the blank, and select the option to open the command window here!

03. Then enter the command shown below:

Python-m venv env # create virtual environment command

After that, you will see that there is an env folder in the folder, which is the virtual environment folder we created.

04. Activate the virtual environment:

Env\ Scripts\ activate # activate the virtual environment

After successful activation, there is an extra env in front of it.

02

-

Install Django and create a project

01. Install it in the official library using the installation command that comes with Pyhton.

Pip install django # install the latest version of the django command

Successfully installed django-2.2.2 pytz-2019.1 sqlparse-0.3.0

See this prompt indicating that django has been successfully installed

02. Create a project and its application by using the command of django

Django-admin.py startproject Myblog.

Note: Myblog is the name of the project we are going to create, and the last dot "." it is best not to omit it, which is beneficial to the deployment of the project behind us.

The file structure is as follows:

The Myblog folder contains the following files:

So far, our project has been created successfully!

03. Run the server that comes with Django for debugging to check whether the project is installed successfully

Python manage.py runserver # start the debugger

Local address and port after startup

Enter: http://127.0.0.1:8000 in the browser and see the following interface, indicating that the project was launched successfully.

04. Create a blog application-- blog

Press ctrl+c to exit the startup program just now. If pressing once does not work, you can press it several times more.

Python manage.py startapp blog # create blog Application python manage.py migrate # create Database

05. Create blog applications and databases, create super administrators

Python manage.py createsuperuser

# username Username (leave blank to use 'administrator'): admin # email address Email address: 2539909370@qq.com # Super Admin password is not displayed when typing, so don't make a fuss about Password:Password (again): # prompt the Super Admin to create a successful Superuser created successfully.

6. Start the debugging server

Python manage.py runserver

Enter "http://127.0.0.8:8000/admin/" in the browser to enter the background, and the page shown below indicates success.

Some of the most commonly used commands in the beginner development of django are sorted out as follows:

Create Project: django-admin startproject myblog create Application: python manage.py startapp polls create default Database: python manage.py migrate create Super Admin: python manage.py createsuperuser create Database Migration File: python manage.py makemigrations Migration data: python manage.py migrate

If there is any infringement, please contact support@oschina.cn for deletion.

After reading the above, have you mastered how to install Django and create projects and applications? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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