django框架创建应用操作示例


Posted in Python onSeptember 26, 2019

本文实例讲述了django框架创建应用操作。分享给大家供大家参考,具体如下:

18.1.5  安装Django

安装Django

node2:/root#pip install Django
/usr/local/python27/lib/python2.7/site-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.
 utils.DeprecatedIn23,
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: Django in /usr/local/python27/lib/python2.7/site-packages (1.11.9)
Requirement already satisfied: pytz in /usr/local/python27/lib/python2.7/site-packages (from Django) (2017.2)
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

18.1.6  在Django 中创建项目:

node2:/django/mysite#django-admin.py startproject learning_log
node2:/django/mysite#ls -ltr
total 64
-rwxrwxrwx 1 root root 804 Oct 25 2017 manage.py
-rwxrwxrwx 1 root root 608 Nov 25 2017 query_mysql.py
drwxrwxrwx 3 root root 4096 Nov 27 2017 form
drwxrwxrwx 2 root root 4096 Nov 27 2017 online
-rwxrwxrwx 1 root root 262 Dec 5 2017 test.py
-rwxrwxrwx 1 root root 646 Dec 5 2017 test.pyc
-rwxrwxrwx 1 root root 113 Dec 5 2017 __init__.pyc
drwxrwxrwx 2 root root 4096 Dec 5 2017 home
-rwxrwxrwx 1 root root  0 Dec 5 2017 __init__.py
-rwxrwxrwx 1 root root  27 Dec 5 2017 a1.py
-rwxrwxrwx 1 root root  5 Dec 5 2017 celerybeat.pid
drwxrwxrwx 7 root root 4096 Dec 12 2017 static
drwxrwxrwx 4 root root 4096 Jan 28 2018 blog
drwxrwxrwx 2 root root 4096 Sep 16 2018 portal
drwxrwxrwx 2 root root 4096 Apr 24 10:15 mysite
drwxrwxrwx 4 root root 4096 Apr 25 02:17 news
drwxr-xr-x 3 root root 4096 Apr 25 09:25 learning_log

/django/mysite/learning_log/learning_log

INSTALLED_APPS = (
  'django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
  'learning_log',

18.1.7 创建数据库

Django 将大部分与项目相关的信息都存储在数据库中,因此我们需要创建一个供Django使用的数据库

配置mysql数据库

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'tlcb',
'USER': 'root',
'PASSWORD': '1234567',
'HOST': '192.168.137.3',
'PORT': '3306',
}
}
node2:/django/mysite/learning_log#python 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 sessions.0001_initial... OK
node2:/django/mysite/learning_log#

18.1.8 创建应用:

django-admin.py startproject learning_log

希望本文所述对大家基于Django框架的Python程序设计有所帮助。

Python 相关文章推荐
python实现网页链接提取的方法分享
Feb 25 Python
初步理解Python进程的信号通讯
Apr 09 Python
详解Python命令行解析工具Argparse
Apr 20 Python
python django 实现验证码的功能实例代码
May 18 Python
python安装pywin32clipboard的操作方法
Jan 24 Python
Python实例方法、类方法、静态方法的区别与作用详解
Mar 25 Python
Python学习笔记之文件的读写操作实例分析
Aug 07 Python
Python3.7 基于 pycryptodome 的AES加密解密、RSA加密解密、加签验签
Dec 04 Python
Pycharm安装并配置jupyter notebook的实现
May 18 Python
Python 使用xlwt模块将多行多列数据循环写入excel文档的操作
Nov 10 Python
如何设置PyCharm中的Python代码模版(推荐)
Nov 20 Python
Python实现猜拳与猜数字游戏的方法详解
Apr 06 Python
Python从入门到精通之环境搭建教程图解
Sep 26 #Python
python性能测量工具cProfile使用解析
Sep 26 #Python
python使用socket 先读取长度,在读取报文内容示例
Sep 26 #Python
用python写测试数据文件过程解析
Sep 25 #Python
Python使用grequests(gevent+requests)并发发送请求过程解析
Sep 25 #Python
给大家整理了19个pythonic的编程习惯(小结)
Sep 25 #Python
Python 图像对比度增强的几种方法(小结)
Sep 25 #Python
You might like
PHP中用正则表达式清除字符串的空白
2011/01/17 PHP
解析:php调用MsSQL存储过程使用内置RETVAL获取过程中的return值
2013/07/03 PHP
php制作中间带自己定义图片二维码的方法
2014/01/27 PHP
PHP生成plist数据的方法
2015/06/16 PHP
ZF框架实现发送邮件的方法
2015/12/03 PHP
php+layui数据表格实现数据分页渲染代码
2019/10/26 PHP
PHP7变量处理机制修改
2021/03/09 PHP
三种动态加载js的jquery实例代码另附去除js方法
2014/04/30 Javascript
jQuery代码实现表格中点击相应行变色功能
2016/05/09 Javascript
AngularJS入门教程之表格实例详解
2016/07/27 Javascript
AngularJS自定义指令详解(有分页插件代码)
2017/06/12 Javascript
ES6新增的math,Number方法
2017/08/06 Javascript
JavaScript函数绑定用法实例分析
2017/11/14 Javascript
vue模式history下在iis中配置流程
2019/04/17 Javascript
node.js处理前端提交的GET请求
2019/08/30 Javascript
js全屏事件fullscreenchange 实现全屏、退出全屏操作
2019/09/17 Javascript
基于layui的table插件进行复选框联动功能的实现方法
2019/09/19 Javascript
原生JS实现烟花效果
2020/03/10 Javascript
Python微信企业号开发之回调模式接收微信端客户端发送消息及被动返回消息示例
2017/08/21 Python
Python3 循环语句(for、while、break、range等)
2017/11/20 Python
python thrift搭建服务端和客户端测试程序
2018/01/17 Python
python对于requests的封装方法详解
2019/01/03 Python
python实现两个经纬度点之间的距离和方位角的方法
2019/07/05 Python
Django Haystack 全文检索与关键词高亮的实现
2020/02/17 Python
解决pycharm安装第三方库失败的问题
2020/05/09 Python
python使用建议技巧分享(三)
2020/08/18 Python
医学院学生求职简历的自我评价
2013/10/24 职场文书
十岁生日家长答谢词
2014/01/17 职场文书
父亲八十大寿答谢词
2014/01/23 职场文书
物流专员岗位职责
2014/02/17 职场文书
中班中秋节活动反思
2014/02/18 职场文书
学习党的群众路线教育实践活动心得体会
2014/03/01 职场文书
园林技术专业求职信
2014/07/28 职场文书
经典爱情感言
2015/08/03 职场文书
dubbo服务整合zipkin详解
2021/07/26 Java/Android
MySQL中dd::columns表结构转table过程及应用详解
2022/09/23 MySQL