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的Tornado框架实现一个一对一聊天的程序
Apr 25 Python
Python中subprocess的简单使用示例
Jul 28 Python
Python xlwt设置excel单元格字体及格式
Apr 18 Python
python简单商城购物车实例代码
Mar 15 Python
Django Web开发中django-debug-toolbar的配置以及使用
May 06 Python
Python实现获取邮箱内容并解析的方法示例
Jun 16 Python
python实现windows壁纸定期更换功能
Jan 21 Python
Python Django 封装分页成通用的模块详解
Aug 21 Python
浅析matlab中imadjust函数
Feb 27 Python
python如何在word中存储本地图片
Apr 07 Python
教你使用Pandas直接核算Excel中快递费用
May 12 Python
Python爬虫中urllib3与urllib的区别是什么
Jul 21 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
基于数据库的在线人数,日访问量等统计
2006/10/09 PHP
php实现mysql数据库备份类
2008/03/20 PHP
Yii框架中jquery表单验证插件用法示例
2016/10/18 PHP
防止浏览器记住用户名及密码的简单实用方法
2013/04/22 Javascript
js replace替换所有匹配的字符串
2014/02/13 Javascript
js 采用delete实现继承示例代码
2014/05/20 Javascript
js和jquery中循环的退出和继续下一个循环
2014/09/03 Javascript
Javascript验证Visa和MasterCard信用卡号的方法
2015/07/27 Javascript
Javascript的表单验证-初识正则表达式
2016/03/18 Javascript
微信小程序 地图定位简单实例
2016/10/14 Javascript
用AngularJS来实现监察表单按钮的禁用效果
2016/11/02 Javascript
详解使用vue脚手架工具搭建vue-webpack项目
2017/05/10 Javascript
ionic3 懒加载
2017/08/16 Javascript
AngularJS+Bootstrap3多级导航菜单的实现代码
2017/08/16 Javascript
仿淘宝JSsearch搜索下拉深度用法
2018/01/15 Javascript
Vue如何实现变量表达式选择器
2021/02/18 Vue.js
[02:08]什么藏在DOTA2 TI9“小紫本”里?斧王历险记告诉你!
2019/05/17 DOTA
python同时给两个收件人发送邮件的方法
2015/04/30 Python
python 实时遍历日志文件
2016/04/12 Python
详谈pandas中agg函数和apply函数的区别
2018/04/20 Python
Django1.9 加载通过ImageField上传的图片方法
2018/05/25 Python
python try 异常处理(史上最全)
2019/03/07 Python
keras.layer.input()用法说明
2020/06/16 Python
Python 2.6.6升级到Python2.7.15的详细步骤
2020/12/14 Python
CSS3轻松实现圆角效果
2017/11/09 HTML / CSS
美国购买和销售礼品卡平台:Raise
2017/01/13 全球购物
澳大利亚领先的在线机械五金、园艺和存储专家:Edisons
2018/03/24 全球购物
西班牙购买行李箱和背包网站:Maletas Greenwich
2019/10/08 全球购物
Gibson London官网:以地道的英国男装而著称
2019/12/06 全球购物
银行求职推荐信范文
2013/11/30 职场文书
我未来的职业规划范文
2014/01/11 职场文书
2014年大学生党课心得体会范文
2014/03/29 职场文书
暑假社会实践心得体会
2014/09/02 职场文书
小学生作文评语集锦
2014/12/25 职场文书
社区五一劳动节活动总结
2015/02/09 职场文书
MySQL优化之如何写出高质量sql语句
2021/05/17 MySQL