Python初学记之Django(二)

python + django + bootstrap 快速web开发初探 附Java/C/C++/机器学习/算法与数据结构/前端/安卓/Python/程序员必读书籍书单大全: 书单导航页(点击右侧 极客侠栈 即可打开个人博客):极客侠栈 ①【Java】学习之路吐血整理技术书从入门到进阶最全50+本(珍藏版) ②【算法数据结构+acm】从入门到进阶吐血整理书单50+本(珍藏版) ③【数据库】从入门到进阶必读18本技术书籍网盘吐血整理网盘(珍藏版) ④【Web前端】从HT... 阅读详情

目录

一、关于MTV

二、管理页面

三、写个POST表单


上一篇:Python初学记之Django_Link2Points的博客-优快云博客

一、关于MTV

  • Model: 模型层,构建和操纵的Web应用的数据,如数据库操作
  • Templetes: 模板层,与用户直接接触的前端html
  • View: 视图层,负责处理用户的请求并返回响应

二、管理页面

# 创建管理员
python manage.py createsuperuser
# 接着输入用户名、邮箱、密码

访问http://ip地址/admin

三、写个POST表单

Templetes(一般Pycharm创建项目时,勾选创建;若无,手动在mysite目录下创建)下新建login.html、index.html

login.html中(在html中嵌入的语言目前看不能执行复杂的操作)

<form action="{% url 'verify_login' %}" method="post">
    <input type="text" name="user_id" required="required" />
    <input type="submit" name="loginBtn" value="登录">
</form>

创建test应用后,在改test目录下views.py中

# 登录页面
def login(request):
    return render(request, "login.html")


# 验证登录
def verify_login(request):
    if request.method == "POST":
        police_id = request.POST.get('user_id')
        # 这里可以设置数据库查询操作(调用models.py写好的函数)
        # 设置session
        request.session['user_id'] = user_id
        # 租期 24 h
        request.session.set_expiry(60 * 60 * 24)
        if not user_id == "":
            return index(request)
    return login(request)

# 主页
def index(request):
    # 获取session并验证, 如无跳转至登录页
    police_info = request.session.get('police_info')
    if police_info is None:
        return login(request)
    return render(request, "index.html", {"data1":"数据","datas1":["数据","数据"]})

在mysite/mysite/urls.py中

from django.contrib import admin
from django.urls import path
from test.views import *
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', verify_login, name="verify_login"),
    path('login.html', login, name="login"),
    path('index.html', index, name="index")
]

Python3搭建Django框架详解       最近在学习python语言,学过python的都知道Django是python web项目中比较好的一个框架,于是我也就去研究了一下,在这里把搭建步骤和遇到的问题给大家分享一下,有什么地方不明吧的也可以加关注我们一起讨论学习。Django框架搭建步骤如下: 1.首先,你需要安装Python环境,我本机是安装的Python3.6.4;以及我们要用的Django,我这里安装的是最新的版本是... 阅读详情

相关推荐

初学者学Django

Django 是一个高级的 Python Web 框架,它鼓励快速开发和干净、实用的设计。对于初学者来说,Django 提供了一个全面的工具集来帮助你构建功能强大的网站。

austinchr3377的博客 845

python-openpyxl设置单元格填充颜色及字体颜色

接上一篇,表合并后需根据某列字段指定值整行填充颜色或设置字体颜色,以下代码为单个表操作,若需操作多表需进行循环读取。

weixin_44808142的博客 1万+

Pycharm+Django之Django学习(1)(初学者)

教学属于博主的自学记录,适合刚学习Django的同学,如果比较熟的就不用look了!!! 以下都是讲在windows上的部署情况; 准备: 1、Python+pycharm(下面是博主使用的版本,可自行安装) 链接:https://pan.baidu.com/s/1th08XXTqf30Oh0-s7QgL1w 密码:r6tc 2、安装Django(可以到官网下载,也可使用Python自带...

xqw10500的博客 1574

python已安装好第三方库,pycharm from openpyxl import Workbook时仍标红的解决办法

settiings>project>project Interpreter>点击+号 搜索要引入的模块,点击install Package

qq_31228567的博客 3558

Abel逆变换及其求解方法

Abel逆变换常应用在轴对称的、光学薄的火焰、羽流或等离子体重建。

weixin_49783507的博客 8371

FFmpeg视频缩放终极指南:从基础命令到保持宽高比的5种实战技巧

本文是FFmpeg视频缩放的终极指南,详细讲解了从基础命令到保持宽高比的5种实战技巧。针对不同平台(如抖音、B站、Instagram)的分辨率要求,提供了具体的参数模板和批量处理脚本,帮助内容创作者高效、精准地调整视频大小,避免画面变形或黑边问题,实现多平台适配。

juice的博客 458

python语言程序设计习题

快乐的数字 描述 编写一个算法来确定一个数字是否“快乐”。 快乐的数字按照如下方式确定:从一个正整数开始,用其每位数的平方之和取代该数,并重复这个过程,直到最后数字要么收敛等于1且一直等于1,要么将无休止地循环下去且最终不会收敛等于1。能够最终收敛等于1的数就是快乐的数字。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪...

qq_40060087的博客 6万+

5分钟搞定!用Keil MDK将STM32F103C8T6工程无缝迁移到ZET6开发板

本文详细介绍了如何在Keil MDK环境下快速将STM32F103C8T6工程迁移到ZET6开发板,涵盖硬件差异对比、工程配置调整、外设适配及编译排错等关键步骤,帮助开发者5分钟内完成工程移植,大幅提升开发效率。

weixin_30879169的博客 409

Python初学记之Django

目录 一、准备工作 虚拟环境,如果是PyCharm可以快速创建 下载Django 二、Django项目操作 配置 一、准备工作 文档:Django 文档 | Django 文档 | Django 虚拟环境,如果是PyCharm可以快速创建 # 下载 pip install virtualenv # 创建 python -m venv django_venv # 启动 ./django_venv/bin/activate # 退出 ./django_venv/bin/deactivat

Link2Points的博客 519

基于TL431与光耦的电压反馈环路优化设计实战

本文深入探讨了基于TL431与光耦的电压反馈环路优化设计实战。文章从理解这对“黄金搭档”的工作原理入手,详细拆解了电压采样电阻网络、偏置电路、光耦工作点设置以及动态补偿网络的设计心法与计算步骤。重点分享了如何通过RC补偿网络调试,确保环路在各种负载下稳定可靠,并提供了关键的实战避坑指南,帮助工程师解决电源设计中常见的振荡、噪声及可靠性问题。

nginx7reverse的博客 777

Embedding理解及keras中Embedding参数详解,代码案例说明

Embedding理解 嵌入层将正整数(下标)转换为具有固定大小的向量 ------官网 词嵌入是一种语义空间到向量空间的映射,简单说就是把每个词语都转换为固定维数的向量,并且保证语义接近的两个词转化为向量后,这两个向量的相似度也高。 举例说明embedding过程: “Could have done better” 通过索引对该句子进行编码,每个单词分配一个索引,上面的句子就会变成这样: 122 8 114 12 创建嵌入矩阵,即每一个索引需要分配多少维向量,也就是说每个词需要转化为多少维

wo的博客 1万+

【Django】Python+Django 图文教程

Django新手图文教程 本文面向:有python基础,刚接触web框架的初学者。  环境:windows7   python3.5.1  pycharm专业版  Django 1.10版  pip3一、Django简介  百度百科:开放源代码的Web应用框架,由Python语言编写......  重点:一个大而全的框架,啥都替你考虑好了。1. web框架介绍  具体介绍Django之前,必...

前端进阶之路 | 中大厂、外企、国企内推 | 面试培训 | 简历修改 2万+

【RT-DETR有效改进】利用EMAttention加深网络深度提高模型特征提取能力(特征选择模块)

本文给大家带来的改进机制是EMAttention注意力机制,它的核心思想是,重塑部分通道到批次维度,并将通道维度分组为多个子特征,以保留每个通道的信息并减少计算开销。EMA模块通过编码全局信息来重新校准每个并行分支中的通道权重,并通过跨维度交互来捕获像素级别的关系。本文改进是基于ResNet18、ResNet34、ResNet50、ResNet101,文章中均以提供,本专栏的改进内容全网独一份深度改进RT-DETR非那种无效Neck部分改进,

Snu77的博客 3170

django 最佳实践_5本适合初学者的最佳Django书

django 最佳实践Here you will find list of best django books for beginners to learn. 在这里,您将找到最佳django书籍清单,供初学者学习。 If you’re eager to learn Django as it is so popular nowadays for its simplicity, then you...

culing2941的博客 7814

glibc: GLIBC_2.28‘ not found

这个时候,应该怎么解决,因为当前运行的机器是低版本,而程序是高版本,解决方法,或者是将程序降级,或者将当前系统升级。在一个glibc的接口版本是GLIBC_2.25的lab上,运行不了在2.28上编译的程序。看哪一个方便,但是不能通过 临时复制libc.so 文件来解决,因为会遇到下面的错误。所以如果是简单解决就是按照低版本的应用程序,来适配当前系统的glibc版本。比如下面的程序运行提示。

mzhan017的博客 2405

一文让你轻松理解802.11ax RU的概念

RU

1042484520@qq.com(邮箱) 3368

python django的一些初学心得

python中的django的初学心得,只限后端,前端很少。附带公司实际开发经验

weixin_43837462的博客 983

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Django初学者教程

This is the first post in the Django tutorials series. Today we’ll be learning about the Django environment and will set up our first Django web application on a localhost. This Django tutorial is for...

从零开始的教程世界 1450

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Django+Scrapy 小说网站初学者(二)

scrapy.Django

weixin_56938118的博客 1481

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

给 Python 初学者:从零入门 Django 开发网站教程

对于 Python 程序员来说,进行 Web开发有很多现成的框架可供使用,比如Django、Flask、Tornado。而其中,Django 可能是最...

实验楼 1066

Python Django系列—入门实例(二)

Python Django系列—入门实例(二)

深圳市多克创新科技有限公司 1270

记一次:Python的学习笔记二(Django项目1)

所以学习的话也是推荐排名靠前的,各个框架的优缺点不做展开讲解。admin为自动后台管理,再次打开settings.py文件,找到INSTALLED_APPS这个元组,观察其第一行的‘django.contirb.admin'是否被注释(旧版好像会被注释,需要自己去掉注释,新版不会)。创建应用,在 Django 中,每一个应用(app)都是一个 Python 包,并且遵循着相同的约定,app的存放位置可以是任何地点,但是通常都将它们放在与manage.py脚本同级的目录下,这样方便导入文件。

敬业小码哥的博客 517

python框架django书籍_有Python基础,刚接触web框架的Django初学者。

本文面向:有Python基础,刚接触web框架的Django初学者。环境:windows7 python3.5.1 pycharm Django 1.10版 pip3一、Django简介百度百科:一个开放源代码的Web框架,由Python语言编写......重点:一个大而全的框架,啥都替你考虑好了。1. web框架介绍具体介绍Django之前,必须先介绍WEB框架的概念。web框架: 别人已经设定...

weixin_39669982的博客 337

python-django从入门到入土(二)

django入门到入土环境配置以及初级实践

玉江仙的博客 853
上一篇: Python初学记之Django
下一篇: PHP 简易文件系统
Link2Points
博客等级 码龄7年 152粉丝 80原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值