django开发:

1 安装python环境
官网下载后安装 或者安装anaconda
conda env list

anaconda相关操作:

查看环境

conda env list
创建环境

conda create -n python36 python=3.6
进入环境

source activate python36
activate python36 # windows下
搜索包

conda search mxnet*
指定环境,查看已安装的包

conda list -n python36
指定环境,安装指定版本的包

conda install -n python36 mxnet==1.0.0
指定环境,更新包

conda update -n python36 mxnet
指定环境,删除包

conda remove -n python36 mxnet
导出环境为yml

conda env export > environment.yml
根据yml创建环境

conda env create -f environment.yml
对yml文件修改后更新环境

conda env update -f environment.yml
退出环境

source deactivate
deactivate # windows下
复制环境

conda create -n python36 --clone python36_new
删除环境

conda remove -n python36 --all
更改镜像源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
修改后可以在~/.condarc配置文件中可以看到相应信息

pip修改镜像源(修改~/.pip/pip.conf配置文件)

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

2 安装 django

pip install django
查看是否安装成功: django-admin

3 初始化django项目
django-admin startprojetc 创建项目
django-admin startapp 启动运用
makemigrations 创建迁移文件
migrate 执行迁移

django运用和项目的区别:项目可以直接运行,项目可以包含若干个运用

建立模型
models文件
from django.db import models

# Create your models here.
class Article(models Model):
article_id = models.AutoField(primary_key=True)
title = models.TextField()
brief_content = models.TextField()
content = models.TextField()
created_at = models.DateTimeField(auto_now=True)

python manage.py makemigrations 生成迁移文件
python manage.py migrate 执行迁移

python manage.py shell shell环境进入

In [1]: from blog.models import Article

In [2]: a = Article()

In [3]: a.title = "biaoti"

In [4]: a.breif_content = "zhaiyao"

In [5]: a.content="详细内容"

In [6]: a.created_at="2019-01-01"

In [7]: print(a)
Article object (None)

In [8]: a.save()

In [9]: articles = Article.objects.all()

In [10]: article = articles[0]

In [11]: article.title
Out[11]: 'biaoti'

In [12]: article.brief_content
Out[12]: ''

In [13]: article.brief_content = 'zhaiyao'

In [14]: article.save()

In [15]: article.brief_content
Out[15]: 'zhaiyao'

django的admin模块

python manage.py createsuperuser 创建超级管理员

配置中文

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'PRC'

注册文章模型到后台 编辑admin.py
from django.contrib import admin

# Register your models here.
from .models import Article

admin.site.register(Article) 然后从其服务 就会发现有文章的了

列表显示对象 改为显示标题
更改models里面的类 增加
def __str__(self):
return self.title

显示多个字段

admin.py
from django.contrib import admin

# Register your models here.
from . import models

class ArticleAdmin(admin.ModelAdmin):
list_display = ["title","brief_content","content","created_at"]
list_display_link = ["id","title"]

admin.site.register(models.Article, ArticleAdmin)

过滤器

from django.contrib import admin

# Register your models here.
from . import models

class ArticleAdmin(admin.ModelAdmin):
list_display = ["title","brief_content","content","created_at"]
list_display_link = ["id","title"]
list_filter = ('created_at',)

admin.site.register(models.Article, ArticleAdmin)

django learn step的更多相关文章

  1. [Windows Azure] Learn SQL Reporting on Windows Azure (9-Step Tutorial)

    Learn SQL Reporting on Windows Azure (9-Step Tutorial) 4 out of 4 rated this helpful - Rate this top ...

  2. User Authentication with Angular and ASP.NET Core

    User authentication is a fundamental part of any meaningful application. Unfortunately, implementing ...

  3. Docker 搭建一个Docker应用栈

    Docker应用栈结构图 Build Django容器 编写docker-file FROM django RUN pip install redis build django-with-redis ...

  4. [转]UiPath Invoke Code

    本文转自:https://dotnetbasic.com/2019/08/uipath-invoke-code.html We will learn step by step tutorial for ...

  5. [转]uipath orchestrator installation

    本文转自:https://dotnetbasic.com/2019/08/uipath-orchestrator-installation.html UiPath Orchestrator Insta ...

  6. [转]UiPath Deployment Architecture

    本文转自:https://dotnetbasic.com/2019/08/uipath-deployment-architecture.html We will learn step by step ...

  7. Step by Step Learn Python(1)

    print "Hello World!" action = raw_input("please select your action{1, 2, 3, 4, 5, 6, ...

  8. Writing your first Django app, part 1(转)

    Let’s learn by example. Throughout this tutorial, we’ll walk you through the creation of a basic pol ...

  9. win7下,使用django运行django-admin.py无法创建网站

    安装django的步骤: 1.安装python,选择默认安装在c盘即可.设置环境变量path,值添加python的安装路径. 2.下载ez_setup.py,下载地址:http://peak.tele ...

随机推荐

  1. plsql查询数据库-中文显示问号问题

    解决方法: 设置本地环境变量 :NLS_LANG=AMERICAN_AMERICA.ZHS16GBK https://blog.csdn.net/github_38358734/article/det ...

  2. git 项目最常用命令总结

    本文为博主原创,未经允许不得转载: 1.查看git基础配置信息 1.查看用户名和邮箱地址 git config user.name   git config user.email 2.修改用户名和邮箱 ...

  3. Xamarin图表开发基础教程(12)OxyPlot框架支持的金融图表类型

    Xamarin图表开发基础教程(12)OxyPlot框架支持的金融图表类型 OxyPlot组件中支持5种类型的金融图表,它们分别为销量图.高低图.股票K线图.股票走势图和旧式股票图,如图1.20~1. ...

  4. 027_MacOs上如何将多页word打印到一个页面上

    工作中需要把word的多页面内容打印到同一张A4纸,所以就想了办法,首先word导出到pdf. 然后使用MacOs默认的PDF阅读器进行多页打印. 操作如下: 文件-打印布局选择每张纸需要打印的页数左 ...

  5. h5开发安卓机型点击输入框调起输入法,输入框被键盘遮挡的解决方法

    前言: 从以前的项目中找一个问题的解决方案,顺带找到了这个安卓机型调起输入法,页面没有自动上滑导致输入框被弹起的键盘遮挡的解决方案.这个问题只有安卓机型页面中的输入框处于底部(也就是底部键盘区域)的时 ...

  6. CefSharp在高DPI的屏幕上出现黑边(winform)

    目录 问题现象 解决办法 1.将cefsharp的gpu设置为无效,(后遗症,h5动画会出现卡顿现象,慎用) 2.将屏幕的DPI置为96(缩放比例为100%)(后遗症,不可能每个电脑都去配置) 3.支 ...

  7. 【WebSocket】WebSocket快速入门

    WebSocket介绍 WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. WebSocket 使得客户端和服务器之间的数据交换变得更加简单,允许服务端主动 ...

  8. 【转帖】处理器的三国时代:DR公司盛气凌人,IBM转身成就微软

    处理器的三国时代:DR公司盛气凌人,IBM转身成就微软 https://www.eefocus.com/mcu-dsp/360555 <处理器史话>之五 2016-04-06 15:24  ...

  9. CF1016D Vasya And The Matrix

    题目描述 我们有一个 n * m 的矩阵,现在我会告诉你每一行和每一列的异或和请求出任意一种可能的矩阵 数据范围 1<=n,m<=100输入数据确保在int范围内 输入输出格式: 输入格式 ...

  10. Django——用户认证

    Django--用户认证 用户与Authentication(身份验证) Django 用户认证系统处理用户帐号,组,权限以及基于cookie的用户会话. 这个系统一般被称为 auth/auth (认 ...