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 in ubuntu virtual environment

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

In this issue, the editor will bring you about how to install Django in the ubuntu virtual environment. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1. Install the virtual environment

Sudo pip install virtualenv

2. Create a virtual environment

Mkvirtualenv file name-p python3 (this is the python version)

Some friends have questions about "mkvirtualenv file name". This is the python2 version by default.

However, it should be noted that the operation here should be carried out on the Internet, and a copy of the python should be copied to the virtual environment.

3. Switch virtual environment

Workon file name

Can work in a virtual environment

Note: delete virtual environment

Rmvirtualenv file name

Exit environment

Deactivate

Installation of Django in virtual environment and establishment of project 1. Install Django

Pip install django = = installation version number

2. Create a project

Django_admin startproject + Project name

There are two files under the project (one is the folder with the same name of the project and the other is the manage.py file): the overall management file of the manage.py project, through which the folder of the same name of the entire project is managed: the overall configuration folder of the settings.py project, the urls.py project, the url configuration file, the entry of the wsgi.py project and the web server

3. Run the server

Python manage.py runserver + port name (default is 8000)

After running successfully, you can confirm whether it is running successfully by going to the browser (127.0.0.1: Port name).

4. Create a module

After you have successfully created the project, you can pass under the project:

Python manage.py startapp + module name

To create a module

5. Register sub-module

In the setting.py file under the folder with the same name

Add "module name. Apps. Class name" in the last line.

6. Define the table name and field name

Class name-table name (actually the table name is module name _ class name) attribute name-field name

7. Register the designed table in admin.py

8. Migrate the database table (each time the database table is modified, there are two steps to do it.)

Python manage.py makemigrations

Generate migration files (in file migrations)

9. Execution of migration documents

Python manage.py migrate

Execute the migration file

10. Backstage display

After executing the migration file, you can set up a Super Admin account to manage and view the table in the background.

Python manage.py createsuperuser

If you want django to support the Chinese interface, modify it in the setting.py file:

LANGUAGE-CODE = 'zh-Hans'// set Chinese TIME_ZONE='Asia/Shanghai'// setting time zone (Shanghai)

11. Database configuration

If we want to be able to modify the contents of the database at the front end, we need to configure the database.

The above setting is configured in the setting.py file

12. Add drivers

After configuring the database, we need to add the driver to the _ _ init__.py file in the same name folder of the project, as shown in the figure:

The above is the editor for you to share how to install Django in the ubuntu virtual environment, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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

Servers

Wechat

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

12
Report