Django2.0.1开发框架搭建

2018-01-12 11:54:21来源:cnblogs.com作者:_York人点击

分享

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 adminadmin.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 migrateOperations to perform:  Apply all migrations: admin, auth, contenttypes, sessionsRunning 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的开发环境可以运行了

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台