Django2.0.1开发框架搭建

栏目: Python · 发布时间: 6年前

内容简介:Django2.0.1开发框架搭建

1、使用vs2017创建空白django项目

Django2.0.1开发框架搭建

2、右键 python 环境的env---安装python包  升级django到2.0.1和setuptools到38.4.0版本,具体环境如下:

Django2.0.1开发框架搭建

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.

运行程序可看到: Django2.0.1开发框架搭建

进入admin管理页面,支持响应式,赞,

Django2.0.1开发框架搭建

至此一个简单的django 2.0.1的开发环境可以运行了


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Refactoring

Refactoring

Martin Fowler、Kent Beck、John Brant、William Opdyke、Don Roberts / Addison-Wesley Professional / 1999-7-8 / USD 64.99

Refactoring is about improving the design of existing code. It is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its int......一起来看看 《Refactoring》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

随机密码生成器
随机密码生成器

多种字符组合密码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试