"Python3.6+django2.0+xadmin2.0 Series Tutorial One" Environment construction and project creation

Source: Internet
Author: User

As a result of the work needs, contact the django+xadmin framework of the big half a year, has not been empty on this piece of related carding. Recently under the encouragement of colleagues, in this share the author's study and work experience it.

Well, don't say much, the following starts to get to the point:

Environmental requirements:

The author's working system environment: MAC 10.13.4+python3.6.x+django2.0.x+xadmin2.0

Therefore, this series of tutorials is based on this combination to explain. Other system versions are also basic, there are a small number of incompatible places please test yourself.

One, Django and xadmin installation

You can use the PIP command to install or download the installation Pack Python command installation directly:

pip3 Install Djangopip3 install git+git://github.com/sshwsfc/[email protected]

Since there are some compatibility bugs in the official version of xadmin2.0, I have made some changes to the source code.

After loading the official version of Django and Xadmin, replace the author's Xadmin repair version with the original installation directory of Xadmin.

More detailed installation process no longer repeat, it takes a whole day to elaborate.

Ii. creating a project using Pycharm

1, open Pycharm, the first time you create a project, we choose Create New project

2, according to the order of the diagram configuration, location and application name can be customized according to their own needs, project resolver the author chooses the system environment path here. Create the project after you have set it all up.

3, the creation of a good project looks like this

4. Click the Green start arrow in the upper right corner, OK, our project has run normally.

At the same time, we can run the project under the project directory, execute commands.

0.0. 0.0:8000

Long March took the first step of victory, and then grafted xadmin.

Iii. Retrofit Django Project with Xadmin

1, first, look at the structure of the project

manage.py is the Web site's startup file, generally do not need to change.
The demo folder is the Web Site configuration folder, we need to manipulate the files mainly include: settings.py and urls.py
Settings.py is the main configuration file for the site
urls.py is a routing file
The app folder is the module created by default when creating a project, and the main development is here.

2, the following start to reform, first to modify url.py

# From django.contrib Import admin Import Xadmin  from Import Path  from Import Settings  from Import  = [    #  path (' admin/', admin.site.urls),    path (r' ) , Xadmin.site.urls),]

3, then modify the settings.py, add 127.0.0.1 Whitelist

allowed_hosts = ['127.0.0.1']

4, modify Installed_apps, add xadmin related components

Add App.apps.AppConfig at the top, then Xadmin and crispy_forms

Installed_apps = [    'App.apps.AppConfig',    'Xadmin',    'Django.contrib.admin',    'Django.contrib.auth',    'Django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'Django.contrib.staticfiles',    'crispy_forms',]

5, so that we can let the Xadmin project run up. Try

Click to log in, you will find that a mistake was reported

The above hint is that there is no user table. It turns out that we haven't initialized the database yet.

6. Initialize the database

When the project is created, the default is to use the Sqlite3 database, and we can also specify that it use the MySQL database and modify the DATABASES

DATABASES = {    'default': {        #' ENGINE ': ' Django.db.backends.sqlite3 ',        #' NAME ': Os.path.join (Base_dir, ' db.sqlite3 '),        'ENGINE':'Django.db.backends.mysql', # Database engine'NAME':'Demo',        'USER':'Root',        'PASSWORD':'123456',        'HOST':'127.0.0.1',        'PORT':'3306',        'OPTIONS': {            'Init_command':"SET sql_mode= ' strict_trans_tables ';" # command to initialize the database        }    }}

Run the Database Migration command

Python3 manage.py Migrate

7, in addition, we have to establish a Super Administrator account, set up a good account password mailbox information

Python3 manage.py Createsuperuser

8, good, everything has, the following can be smoothly into the management interface

9, now this interface is English, it seems to be a bit not used to it? Let's make it appear in Chinese.

Add a line of code at the beginning of the settings.py file

 from Import Ugettext_lazy as _

Modify Language_code and LANGUAGES

Language_code ='Zh-hans'LANGUAGES= [    ('en', _('中文版')),    ('Zh-hans', _('Simplified Chinese')),    ('zh-hant', _('Traditional Chinese')),]

10, re-run, OK, we are familiar with the Chinese interface in front of the present.

Well, it's not too early, it's time to go home from work. In the next section, we will create the model.

"Python3.6+django2.0+xadmin2.0 Series Tutorial One" Environment construction and project creation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.