django learn step
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的更多相关文章
- [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 ...
- User Authentication with Angular and ASP.NET Core
User authentication is a fundamental part of any meaningful application. Unfortunately, implementing ...
- Docker 搭建一个Docker应用栈
Docker应用栈结构图 Build Django容器 编写docker-file FROM django RUN pip install redis build django-with-redis ...
- [转]UiPath Invoke Code
本文转自:https://dotnetbasic.com/2019/08/uipath-invoke-code.html We will learn step by step tutorial for ...
- [转]uipath orchestrator installation
本文转自:https://dotnetbasic.com/2019/08/uipath-orchestrator-installation.html UiPath Orchestrator Insta ...
- [转]UiPath Deployment Architecture
本文转自:https://dotnetbasic.com/2019/08/uipath-deployment-architecture.html We will learn step by step ...
- Step by Step Learn Python(1)
print "Hello World!" action = raw_input("please select your action{1, 2, 3, 4, 5, 6, ...
- 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 ...
- win7下,使用django运行django-admin.py无法创建网站
安装django的步骤: 1.安装python,选择默认安装在c盘即可.设置环境变量path,值添加python的安装路径. 2.下载ez_setup.py,下载地址:http://peak.tele ...
随机推荐
- bean名称相同冲突Annotation-specified bean name 'xx' for bean class [xxx] conflicts with existing, non-compatible bean definition of same name and class[xxx]
工程中引入其他工程的包,由于两个工程中有重名的两个bean,导致在启动时提示如下错误: 根据bean名称在ide中查找,找到这两个重名的类,可以看到由于这两个类使用@Service标注,此时如果不使用 ...
- window上可以执行的shell脚本,复制到linux上执行报错了
原因:.sh脚本在windows系统下用记事本文件编写的.不同系统的编码格式引起的. 解决方法:修改.sh文件格式 (1)使用vi工具vi build_android.sh (2)利用如下命令查看文件 ...
- Redis慢日志查询
Redis slowlog 是个什么 redis的slow log记录了那些执行时间超过规定时长的请求.执行时间不包括I/O操作(比如与客户端进行网络通信等),只是命令的实际执行时间(期间线程会被阻塞 ...
- 阿里云盾AliYunDun服务IO超高
停止阿里云盾AliYunDun服务解决大量写磁盘问题-小内存ECS服务器 阿里云数据库在没备案,涉及大量IO操作时会自动启动阿里云盾这个服务,会导致服务器变得很卡,一直持续百分之99,一顿重启没有什么 ...
- VS2019/VS2017设置默认管理员权限启动
找到vs安装目录下的:C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe 右键- ...
- k8s 使用本地镜像的时候
k8s默认会从远端拉取镜像,其配置参数imagePullPolicy为Always containers: - name: demo image: image imagePullPolicy: Nev ...
- Java开发笔记(一百三十五)Swing的文件对话框
除了常规的提示对话框,还有一种对话框也很常见,它叫做文件对话框.文件对话框又分为两小类:打开文件的对话框.保存文件的对话框,但在Swing中它们都用类型JFileChooser来表达.下面是JFile ...
- 【C++札记】指针数组和数组指针
指针数组: 存储指针的数组,数组找那个的每个一元素都是指针 例: int* p1[4],p2[0]是一个指向int类型的指针 char* p2[4],p1[0]是一个指向char类型的指针 数组指针: ...
- websocket 函数
函数名 描述 socket_accept() 接受一个Socket连接 socket_bind() 把socket绑定在一个IP地址和端口上 socket_clear_error() 清除socket ...
- kafka和zookeeper安装部署(版本弄不好就是坑)
yum install -y unzip zip 配置host vi /etc/host172.19.68.10 zk1 1. zookeeper zookeeper下载地址 http://mirro ...