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

What is the command line of django admin in the Django framework?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

What is the command line of django admin in Django framework? for this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

4.11 loaddata

Function: load data into the database. Syntax: django-admin loaddata fixture [fixture...] Example: create the fixture file question.json and place it in the manage.py sibling directory with the following contents.

Execute the loaddata command, as shown in the following figure.

The execution result is shown in the following figure.

Note that fixture is a serialized data file that contains json and xml in the file format. Django can only find fixture from three types of locations: the fixtures folder under the application. The path specified by FIXTURE_DIRS in the configuration file. Fixture file path. The Loaddata command can find that fixture,Loaddata supports compressed formats such as zip, gz, and bz2 in the compressed file, such as executing the following command:

Django-admin loaddata mydata.json

This command will look for mydata.json, mydata.json.zip, mydata.json.gz, or mydata.json.bz2 at the same time until the first mydata.json file is found. It is important to note that fixture files of different types with the same name cannot be placed under the same path, such as mydata.json and mydata.xml.

4.12 makemessages

Purpose: find the entire source code path to find all the translated strings and generate a new message file or update an existing message file. Syntax: before introducing the code example, django-admin makemessages first modifies index.html to add a translation string:

Then create a new script file trans.js under the polls\ templates\ polls\ folder with the following contents (the script has no practical meaning and is only used to demonstrate the makemessages command):

Example 1: generate a Chinese translation file, as shown in the following figure.

Example 2: use the domain parameter to generate a Chinese translation file for the js script. The Domain parameter accepts two values:

Django: this parameter is used to find translation strings from * .py, * .html, and * .txt files.

Djangojs: this parameter is used to find the translation string from the * .js file. When you specify the djangojs parameter, make sure that the js file is under the tempaltes folder, otherwise you need to use the outer chain to reference the script file in the template.

4.13 startproject

Purpose: to create a Django project. Syntax: the django-admin startproject name [directory] command creates a folder in the current directory by default, which contains the manage.py file and the project folder, and the settings.py file and other necessary files under the project folder.

4.14 startapp

Purpose: to create a Django application.

Syntax: django-admin startapp name [directory] optional parameters:

-- template TEMPLATE

To import an external application template, TEMPLATE can be the path that contains the template file, the path that contains the package, or URL. For example, the following command copies the template file under the my_app_template path to the myapp application:

Django-admin startapp-template=/Users/jezdez/Code/my_app_template myapp

The following command copies the templates of other projects on GitHub to the myapp application:

4.15 runserver

Purpose: start a lightweight Web server on the current machine. The default server port number is 8000. Syntax: django-admin runserver [addrport] example:

Django-admin runserverdjango-admin runserver 1.2.3.4:8000django-admin runserver 7000django-admin runserver [2001:0db8:1234:5678::9]: 70004.16 sendtestemail

Purpose: send a test message to check whether the mailbox settings are correct. Syntax: django-admin sendtestemail foo@example.com bar@example.com

Example: this example takes the QQ mail service as an example to show how to send mail in Django. Set up the QQ mail service in settings.py:

After completing the above configuration, execute the following command to test the mail function:

Python manage.py sendtestemail destination email address

4.17 shell

Function: start a Python interaction window. Syntax:

Django-admin shell-- interface {ipython,bpython,python}

Django-admin shell-- I {ipython,bpython,python}

By default, Django uses ipython or bpython to start interactive mode, and if both interactive tools are installed, you need to specify which one to use when executing the shell command. You can use pip to install the above interactive tools, such as installing ipython:pip install ipython

Example: enter a command, as shown in the following figure.

The answer to the question about the command line of django admin in the Django framework is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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