Django basic commands
This section is mainly to let you know some of the most basic commands of django. Please try to remember them and practice more
1. New A django project
django-admin.py startproject project-name
A project is a project, project-name project name, change it to your own, it must comply with Python's variable naming rules (Start with an underscore or a letter)
2. Create a new app
python manage.py startapp app-name 或 django-admin.py startapp app-name
Generally, a project has multiple apps, of course they are universal Apps can also be used in multiple projects.
3. Synchronize database
python manage.py syncdb 注意:Django 1.7.1及以上的版本需要用以下命令 python manage.py makemigrations python manage.py migrate
This method can create a table when you add a new class in models.py When you run it, the table will be automatically created in the database without having to create it manually.
Note: To modify existing models, versions of Django before Django 1.7 cannot automatically change the table structure. However, there is a third-party tool south. For details, see the Django database migration section.
4. Use the development server
The development server is used during development. Generally, it will automatically restart after modifying the code, which is convenient for debugging and development. However, due to performance issues, it is recommended to only use it for testing and not Used in production environment.
python manage.py runserver # 当提示端口被占用的时候,可以用其它端口: python manage.py runserver 8001 python manage.py runserver 9999 (当然也可以kill掉占用端口的进程) # 监听所有可用 ip (电脑可能有一个或多个内网ip,一个或多个外网ip,即有多个ip地址) python manage.py runserver 0.0.0.0:8000 # 如果是外网或者局域网电脑上可以用其它电脑查看开发服务器 # 访问对应的 ip加端口,比如 http://www.php.cn/:8000
5. Clear the database
python manage.py flush
This command will ask yes Yes or no, choosing yes will clear all the data, leaving only an empty table.
6. Create super administrator
python manage.py createsuperuser # 按照提示输入用户名和对应的密码就好了邮箱可以留空,用户名和密码必填 # 修改 用户密码可以用: python manage.py changepassword username
7. Export data Import data
python manage.py dumpdata appname > appname.json python manage.py loaddata appname.json
For details on data operations, see: Data import and data migration. Now you just need to understand how to use it.
8. Django project environment terminal
python manage.py shell
If you install bpython or ipython, their interface will be automatically used. It is recommended to install it. bpython.
The difference between this command and running python or bpython directly to enter the shell is that you can call the API in models.py of the current project in this shell. There are also some small tests that are very convenient for operating data.
9. Database command line
python manage.py dbshell
Django will automatically enter the database set in settings.py, if it is MySQL or postgreSQL will ask for the database user password.
In this terminal you can execute database SQL statements. If you are familiar with SQL, you may like this approach.
10. More commands
Enter python manage.py on the terminal to see a detailed list, which is especially useful when you forget the subname.
The above detailed explanation of commonly used commands in Django is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.
For more articles related to common commands in Django, please pay attention to the PHP Chinese website!

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.