Django1.9.8 + xadmin + Windows Quick Build website

Source: Internet
Author: User
Tags install django pip install django virtual environment virtualenv

1. Create a Python virtual environment
Pip Install Virtualenvwrapper-win
Mkvirtualenv env3.4
Workon env3.4
Deactivate

Pip Install Virtualenv
Virtualenv-p C:\Python27\python.exe env2.7
CD Env2.7\scripts\activate
Deactivate

2. Install Django
Pip Install django==1.9.8

3. Install MySQL python driver
http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

4. Configuring the Databases in setting
Fill in the link database
User name
Password
Host
Database name

1DATABASES = {2     'default': {3         #' ENGINE ': ' Django.db.backends.sqlite3 ',4         'ENGINE':'Django.db.backends.mysql',5         #' NAME ': Os.path.join (Base_dir, ' db.sqlite3 '),6         'NAME':'Learndjango',7         'USER':'Root',8         'PASSWORD':"',9         'HOST':'127.0.0.1',Ten         'OPTIONS': {"Init_command":"SET foreign_key_checks = 0;", }, One  A     } -  -}

5. Generate a Django default data table
Pycharm Tools Run manager.py Task
Makmigrations
Migrate

6. Create a new app (usually new user app)
Tools Run manager.py Task
  1.startapp AppName (users)
Next edit models.py Design Object Properties
User
Inherit the original Abstractuser and add nickname birthday sex address phone number dock like
For avatars using Python-dependent pillow packages to the Imagefiled property
Pip Install Pillow
The previous steps are created when you are finished using
Tools Run manager.py Task
1.makemigrations Apps
2.migrate
Click Run Django Project
Prompts whether to delete the Auth|user table, select Yes

Tools Run manager.py Task

  

  2.startapp AppName (Courses)
The table relationship in Django uses models. ForeignKey to build
Model.py Design Object Properties
Courses (timetable)
1-n (one-to-many) Course Chapters Lesson (chapter table)
1-n (one-to-many) course small chapters (video table)
Lessonrecourse Course Resource Table

  3.startapp AppName (organization)
Model.py Design Object Properties
courseorg (basic information Form for institutions)
Teacher (basic information for teachers)
City (urban information)

  4.startapp AppName (Operation)
Model.py Design Object Properties
Userask (User enquiry form)
Usercoursecomment (user course review form)
Userfav (User Favorites table)
Usermessage (User prompt information table)
Usercourse (User learning Curriculum)

code example

1 classuserprofile (abstractuser):2Nickname = models. Charfield (max_length=, Verbose_name=u"Nickname", default="")3Birthday = models. Datefield (verbose_name=u"Birthday", Null= True, blank=True)4Gender = models. Charfield (choices= ("male", u"male"),("female", u"female")), default="female", max_length= 6, Verbose_name=u"Sex")5Address = models. Charfield (max_length=, Default=u"")6Mobile = models. Charfield (max_length=, Null=true, blank=True)7Image = Models. ImageField (upload_to="image/%y/%m", Default=u"Image/default.png", Max_length= 100)8 9     classMeta:TenVerbose_name = u"User Information" OneVerbose_name_plural =Verbose_name A  -     def __unicode__(self): -         returnSelf.username

7. Register the created app in Install_apps in setting

8. Register the model with the xadmin to quickly build a backend management system
From. Models import object (user)
Import Xadmin
Registry
Class object (user) Admin (object):
List_display = [' attribute list for display in Xadmin ',]
List_filter = [' attribute list is used for filtering in Xadmin ',]
Search_fields = [' attribute list for search in Xadmin ',]
Associated
Xadmin.site.register (User,useradmin)

9. Make a global replacement work logo footer .....
Apps under app are used to modify menu display content Verbose_name = u "XXXXX"
In the init file is the configuration effective default_app_config = "XXX.apps.XXXConfig"

1. Place all apps under the new Apps folder
Need to add apps to the path inside the setting Sys.path.insert (0, Os.path.join (base_dir, ' apps ')

2. Add a code snippet to setting using a static folder
Staticfiles_dirs = [
Os.path.join (Base_dir, ' static ')
]

3. Define Auth_user_model = ' users.userprofile ' to overwrite the original base USER table

4. #USE_TZ = True #True使用UTC时间 False using local time

5. The admin.py under the app is used to register the backend management system
Class Userprofileadmin (admin. Modeladmin):
Registry
Pass
Associated
Admin.site.register (UserProfile, Userprofileadmin)



The Makemigrations app generates a comparison record
#No changes detected in app ' messages ' to register with apps in setting
Migrate Generating data tables


Model Design (ORM):
URL name = ' xdxxx ' on page action={%url ' xdxxx '%}

Django Apps Design
Django Apps Model Design
Django Apps model data sheet generation and modification
User Management
Course Course Management
Organization Organization and instructor Management
Operation User Operations Management (used to resolve circular reference issues)

Some errors encountered with Xadmin
No module named future.utils pip install future
No module named import_export.admin pip install Django-import-export
Cancel foreign key Check

1DATABASES = {2     'default': {3         #' ENGINE ': ' Django.db.backends.sqlite3 ',4         'ENGINE':'Django.db.backends.mysql',5         #' NAME ': Os.path.join (Base_dir, ' db.sqlite3 '),6         'NAME':'Learndjango',7         'USER':'Root',8         'PASSWORD':"',9         'HOST':'127.0.0.1',Ten         'OPTIONS': {"Init_command":"SET foreign_key_checks = 0;", }, One  A     } -  -}


Pycharm add git
Django uses xadmin pip install Xadmin relies on its own installation in Installapp to register the modified URLs as Xadmin

Django1.9.8 + xadmin + Windows Quick Build website

Related Article

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.