Django2.0.1開發框架搭建


1、使用vs2017創建空白django項目

2、右鍵python環境的env---安裝python包  升級django到2.0.1和setuptools到38.4.0版本,具體環境如下:

3、配置路由配置文件urls.py,取消admin注釋,並修改如下,django2.0的配置跟其他版本配置有所不同

"""
Definition of urls for FirstDJProj.
"""

from django.conf.urls import include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = [
    # Examples:
    # url(r'^$', FirstDJProj.views.home, name='home'),
    # url(r'^FirstDJProj/', include('FirstDJProj.FirstDJProj.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url('admin/doc/','django.contrib.admindocs.urls'),

    # Uncomment the next line to enable the admin:
    url('admin/', admin.site.urls),
]

4、admin后台管理漢化

  修改settings.py的LANGUAGE_CODE

LANGUAGE_CODE = 'zh-hans'

5、修改中間件的MIDDLEWARE_CLASS為MIDDLEWARE

中間件的代碼如下:

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

6、右鍵解決方案  python----->django遷移  創建后台管理admin相關的表

  控制台顯示:

正在執行 manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying sessions.0001_initial... OK

7、右鍵解決方案  python----->django創建超級用戶

  輸入用戶名 郵箱 2次輸入密碼 Superuser created successfully.

運行程序可看到:

進入admin管理頁面,支持響應式,贊,

至此一個簡單的django 2.0.1的開發環境可以運行了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM