In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to deploy the Django module", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to deploy the Django module" this article.
In Django, settings related to the global project need to be added in the configuration file settings.py. The author uses MySQL as the background database and has created a database called django_news in MySQL. You need to set DATABASE_ENGINE = "mysql" and DATABASE_NAME = "django_news" in the appropriate location in the settings.py file.
Note here that if you use a SQLite database, Django can automatically create a new database in SQLite based on the name of the database, while in MySQL, PostgreSQL, or other databases, you need to create a database corresponding to the set name first. When using the MySQL database, you need to install MySQL's Python link library MySQLdb-1.2.1. This module can be downloaded from the site http://sourceforge.net/projects/mysql-python/. Currently, the supported Python version is 2.4, so using the MySQL database needs to be developed and run in the Python environment of version 2.4.
The next two items, DATABASE_USER and DATABASE_PASSWORD, require the user to fill in the user name and password to access the database according to the local settings. If the database is installed on another machine or the listening port of the database is changed, you also need to set the DATABASE_HOST address and DATABASE_PORT entry. The Mysql database used by the author is set to:
DATABASE_USER = & apos;django' DATABASE_PASSWORD = & apos;django_password&apos
In order for Django to recognize the application modules added by developers, you need to define the list of applications loaded by the Django project in the INSTALLED_APPS section of the settings.py file. By default, some of the self-contained modules required for the operation of the Django project have been added to the list. We also need to add the application module news.article that we just wrote, and add the django.contrib.admin application module that comes with Django. The modified code is as follows:
Add the required modules
INSTALLED_APPS = (& apos;django.contrib.auth', & apos;django.contrib.contenttypes', & apos;django.contrib.sessions', & apos;django.contrib.sites', & apos;django.contrib.admin', & apos;news.article',)
After adding the admin module, you cannot immediately use Django's admin background management interface. You need to open the urls.py file in the root directory of the News project, and remove the # comment after "# Uncomment this for admin:", so that the URL for the management interface of Django turns to "(admin/', include; ^ admin/', include (& apos;django.contrib.admin.urls&apos)". ), "available, so that when accessing the admin module, Django can successfully resolve the access address and go to the background management interface.
When the changes to the configuration file are complete, you can execute the manage.py syncdb instruction from the command prompt of the News project. Django automatically completes the database mapping of ORM according to the definition of the model, shielding the underlying database details and the writing of SQL queries.
The time has come to showcase the charm of Django, and the Django framework will allow developers to start a magical experience. Following the scrolling prompt after the command execution, Django has automatically created the corresponding tables and fields in the database based on the mapping file we just defined in models. When the command is executed, the user will be prompted to create a "superuser" account to log in to the background management interface automatically created by Django to manage the model. The command prompt to synchronously update the database table when the instruction is executed is shown in figure 2:
Update database tables synchronously when the Django instruction is executed
The way to maintain motivation is to find a little sense of achievement at any time. Let's take a look at what these steps have done. After using the command manage.py runserver to start the Web server that comes with Django, visit the address http://127.0.0.1:8000/admin/ in the browser, log in with the account and password of the superuser user you just created, and the beautiful Django background management interface shown in figure 3 appears in front of you.
Background management interface automatically generated by Django according to the model
In the admin management interface, each models module that has been defined in the application is displayed, and when you click to view, a list of database objects that exist in models is displayed. The background management interface provided by Django makes it easy for users to change or add database fields directly. Let's click "Add" next to the "Lists" item to add new news categories. Type "Sports News" or any other category you like in the title field and save it. Then click "Add" in the "Items" item and fill in the * items of the news. Each Item entry corresponds to a category item in List. The interface for adding Item is shown in figure 4. Because the association between tables is set, the Item management interface of Django will automatically generate content for the added List categories.
Interface for adding news items
The convenient background management interface of Django saves a lot of time for Web developers. At present, only the default background management mode of Django is used.
These are all the contents of the article "how to deploy Django modules". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.