博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
pyCharm django 中新加app
阅读量:5340 次
发布时间:2019-06-15

本文共 10090 字,大约阅读时间需要 33 分钟。

1.在manage.py@djangotest中输入命令:

  1.startapp   realnameauth   ---新建一个app,名字为realnameauth 

2.在 django 项目中的settings.py文件中配置应用:

INSTALLED_APPS = [    'django.contrib.admin',    'django.contrib.auth',    'django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'django.contrib.staticfiles',    'realnameauth '    //新建的app名字    ]

3.把 realnameauth 应用要用到的html页面放到django项目中的templates文件下,命名为realnameauth_form.html

       
real-name-auth json
mid:
authKey:
reqId:
verifyType:
params:
    idNo:
    name:
    bcNo:
    mobile:
    isHandheld:
    realImg:
    gender:
    nation:
    birthday:
    address:
    issuingAuthority:
    validDate:
    expireDate:
    checkValidityPeriod:
idImgSide:
idImg:
bcNo:
{% csrf_token %}

4.在 django 项目中的static/css/style.css,用于配置htm页面显示的样式:

.smart-green {            margin-left: auto;            margin-right: auto;            max-width: 500px;            background: #F8F8F8;            padding: 30px 30px 20px 30px;            font: 12px Arial, Helvetica, sans-serif;            color: #666;            border-radius: 5px;            -webkit-border-radius: 5px;            -moz-border-radius: 5px;        }        .smart-green h1 {            font: 24px "Trebuchet MS", Arial, Helvetica, sans-serif;            padding: 20px 0px 20px 40px;            display: block;            margin: -30px -30px 10px -30px;            color: #FFF;            background: #9DC45F;            text-shadow: 1px 1px 1px #949494;            border-radius: 5px 5px 0px 0px;            -webkit-border-radius: 5px 5px 0px 0px;            -moz-border-radius: 5px 5px 0px 0px;            border-bottom: 1px solid #89AF4C;        }        .smart-green h1 > span {            display: block;            font-size: 11px;            color: #FFF;        }        .smart-green label {            display: block;            margin: 0px 0px 5px;        }        .smart-green label > span {            float: left;            margin-top: 10px;            color: #5E5E5E;        }        .smart-green input[type="text"], .smart-green input[type="email"], .smart-green textarea, .smart-green select {            color: #555;            height: 30px;            line-height: 15px;            width: 100%;            padding: 0px 0px 0px 10px;            margin-top: 2px;            border: 1px solid #E5E5E5;            background: #FBFBFB;            outline: 0;            -webkit-box-shadow: inset 1px 1px 2px rgba(238, 238, 238, 0.2);            box-shadow: inset 1px 1px 2px rgba(238, 238, 238, 0.2);            font: normal 14px/14px Arial, Helvetica, sans-serif;        }        .smart-green textarea {            height: 100px;            padding-top: 10px;        }        .smart-green .button {            background-color: #9DC45F;            border-radius: 5px;            -webkit-border-radius: 5px;            -moz-border-border-radius: 5px;            border: none;            padding: 10px 25px 10px 25px;            color: #FFF;            text-shadow: 1px 1px 1px #949494;        }        .smart-green .button:hover {            background-color: #80A24A;        }        .error-msg{            color: red;            margin-top: 10px;        }        .success-msg{            color: #80A24A;            margin-top: 10px;            margin-bottom: 10px;        }

5.在 django 项目中的settings.py文件中配置静态文件调用路径:

# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/2.0/howto/static-files/STATIC_URL = '/static/'STATICFILES_DIRS = [    os.path.join(BASE_DIR, 'static')   ]

 

6.在realnameauth文件夹下的views.py,用于显示html页面:

 

from django.shortcuts import render from .models import FieldMessages # Create your views here. def InsertData(request):     #添加数据     if request.method == "POST":         mid = request.POST.get('mid','')         authKey = request.POST.get('authKey','')         reqId = request.POST.get('reqId','')         verifyType = request.POST.get('verifyType','')         params_idNo = request.POST.get('idNo','')         params_name = request.POST.get('name','')         params_bcNo = request.POST.get('verify-bcNo','')         params_mobile = request.POST.get('mobile','')         params_isHandheld = request.POST.get('isHandheld','')         params_realImg = request.POST.get('realImg','')         params_gender = request.POST.get('gender','')         params_nation = request.POST.get('nation','')         params_birthday = request.POST.get('birthday','')         params_address = request.POST.get('address','')         params_issuingAuthority = request.POST.get('issuingAuthority','')         params_validDate = request.POST.get('validDate','')         params_expireDate = request.POST.get('expireDate','')         params_checkValidityPeriod = request.POST.get('checkValidityPeriod','')         idImgSide = request.POST.get('idImgSide','')         idImg = request.POST.get('idImg','')         bcNo = request.POST.get('attr-bcNo','')         field_messages = FieldMessages()         field_messages.mid = mid         field_messages.authKey = authKey         field_messages.reqId = reqId         field_messages.verifyType = verifyType         field_messages.params_idNo = params_idNo         field_messages.params_name = params_name         field_messages.params_bcNo = params_bcNo         field_messages.params_mobile = params_mobile         field_messages.params_isHandheld = params_isHandheld         field_messages.params_realImg = params_realImg         field_messages.params_gender = params_gender         field_messages.params_nation = params_nation         field_messages.params_birthday = params_birthday         field_messages.params_address = params_address         field_messages.params_issuingAuthority = params_issuingAuthority         field_messages.params_validDate = params_validDate         field_messages.params_expireDate = params_expireDate         field_messages.params_checkValidityPeriod = params_checkValidityPeriod         field_messages.idImgSide = idImgSide         field_messages.idImg = idImg         field_messages.bcNo = bcNo         field_messages.save()     return render(request, 'realnameauth_form.html')
 
 

7.在django 项目中的urls.py配置url:

"""djangotest URL Configuration The `urlpatterns` list routes URLs to views. For more information please see:     https://docs.djangoproject.com/en/2.0/topics/http/urls/ Examples: Function views     1. Add an import:  from my_app import views     2. Add a URL to urlpatterns:  path('', views.home, name='home') Class-based views     1. Add an import:  from other_app.views import Home     2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home') Including another URLconf     1. Import the include() function: from django.urls import include, path     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path from message.views import getform from realnameauth.views import InsertData  #导入realnameauth的InsertData方法 from realnameauth.views import ReadData  #导入realnameauth的ReadData方法 urlpatterns = [    # path('admin/', admin.site.urls),     path('form/',getform, name='go_form'),     path('realnameauth/',InsertData, name='go_realnameauth'), #realnameauth配置路径     path('realnameauth_read/', ReadData, name='go_realnameauth_read')  # realnameauthread配置路径 ]
 

8.在realnameauth文件夹下的models.py写入models类,来对数据库进行操作:

 

from django.db import models# Create your models here.class FieldMessages(models.Model):    mid = models.CharField(max_length=255, verbose_name=u"传入平台分配的商户id")    authKey = models.TextField(verbose_name=u"应用签名信息")    reqId = models.CharField(max_length=255, verbose_name=u"唯一请求流水号")    verifyType = models.CharField(max_length=255, verbose_name=u"身份验证类型")    params_idNo = models.CharField(max_length=255, verbose_name=u"公民身份证号")    params_name = models.CharField(max_length=255, verbose_name=u"姓名")    params_bcNo = models.CharField(max_length=255, verbose_name=u"银行卡号")    params_mobile = models.CharField(max_length=255, verbose_name=u"手机号码")    params_isHandheld = models.CharField(max_length=255, verbose_name=u"是否为手持身份证照片")    params_realImg = models.TextField(verbose_name=u"真实照片转换为base64格式。base64(原始图片二进制流)。")    params_gender = models.CharField(max_length=255, verbose_name=u"")    params_nation = models.CharField(max_length=255, verbose_name=u"")    params_birthday = models.CharField(max_length=255, verbose_name=u"")    params_address = models.CharField(max_length=255, verbose_name=u"")    params_issuingAuthority = models.CharField(max_length=255, verbose_name=u"")    params_validDate = models.CharField(max_length=255, verbose_name=u"")    params_expireDate = models.CharField(max_length=255, verbose_name=u"")    params_checkValidityPeriod = models.CharField(max_length=255, verbose_name=u"是否验证身份证有效期")    idImgSide = models.TextField(verbose_name=u"身份证图片正反面")    idImg = models.TextField(verbose_name=u"身份证图片数据")    bcNo = models.CharField(max_length=255, verbose_name=u"银行卡号")    class Meta:        verbose_name = "实名认证"

9.运行Task命令:

  1.makemigrations realnameauth   ---预建表

  2.migrate realnameauth   ---把表提交到数据库

 

转载于:https://www.cnblogs.com/jingzaixin/p/8676735.html

你可能感兴趣的文章
Fibsieve`s Fantabulous Birthday LightOJ - 1008(找规律。。)
查看>>
bzoj 1112 treap树
查看>>
22岁了 ^^
查看>>
Web前端浏览器兼容初探
查看>>
HTML5 Audio/Video 标签,属性,方法,事件汇总
查看>>
使用rsync 的 --delete参数删除目标目录比源目录多余的文件
查看>>
展望未来,总结过去10年的程序员生涯,给程序员小弟弟小妹妹们的一些总结性忠告...
查看>>
AMH V4.5 – 基于AMH4.2的第三方开发版
查看>>
Mac下安装npm全局包提示权限不够
查看>>
Web.Config文件配置之配置Session变量的生命周期
查看>>
Java网络编程(读书笔记)
查看>>
mysql 中如何查找相同的数据
查看>>
mysql中的having
查看>>
什么是网页美工
查看>>
EF框架 监控小工具 MiniProfiler
查看>>
HDU1698 just a Hook - 带有lazy标记的线段树
查看>>
T-SQL 数据库数据的高级查询
查看>>
在一个RAC集群中最多支持多少节点
查看>>
怎样把图片资源导入Dll,并且取出来? (转)
查看>>
网络协议 4 - 交换机与 VLAN:办公室太复杂,我要回学校
查看>>