显示年月,注册页面和后台数据交互,不涉及数据库
第一步urls
"""mysite01 URL ConfigurationThe `urlpatterns` list routes URLs to views. For more information please see:https://docs.djangoproject.com/en/1.11/topics/http/urls/ Examples: Function views1. Add an import: from my_app import views2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views1. Add an import: from other_app.views import Home2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf1. Import the include() function: from django.conf.urls import url, include2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from blog import viewsurlpatterns = [url(r'^admin/', admin.site.urls),url(r'^show_time/', views.show_time),url(r'article/(\d{4})$', views.article_year),#$代表以某4位数结尾,如2001,只以他结尾# 无命名分组形式访问# \d一个占位符,占4个如2004,#r代表正则url(r'article/(?P<year>\d{4})/(?P<month>\d{2})', views.article_year_month),#命名分组,就是加上?P<>这种固定格式,且尖括号里内容为函数参数名url(r'register', views.register,name="reg"),#别名reg,以后用它就行 ]
2 views里
from django.shortcuts import render, HttpResponse import time# Create your views here. def show_time(req):# return HttpResponse('Hello')t = time.ctime()# return render(req,"index.html",locals())return render(req, 'index.html', {'time': t}) # 其实就是键值对与locals相同 def article_year(req,year):return HttpResponse("year;%s "%(year)) def article_year_month (req,year,month):#必须与前端urls页面命名相同return HttpResponse("year;%s month:%s" % (year, month)) def register(req):if req.method=="POST":print(req.POST.get("user"))print(req.POST.get("age"))return HttpResponse('success')return render(req,"register.html")#学会使用render
register.html
<!DOCTYPE html> <html lang="en"> <head>{% load staticfiles %}<meta charset="UTF-8"><title>Title</title> </head> <body> <h1 align="center">学生注册页面</h1><form action="{% url 'reg' %}" method="post"align="center"><p>姓名<input type="text"name="user"></p><p>年龄<input type="text"name="age"></p><p>爱好<input type="checkbox"name="hobby"value="1">篮球<input type="checkbox"name="hobby"value="2">足球<input type="checkbox"name="hobby"value="3">网球</p><p><input type="submit">提交</p> </form> </body> </html>
index.html
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title> </head> <body> <h1>hello,tom</h1> <h1>{{ time }}</h1> <script src="/blog/static/jquery-3.1.1.js"></script>//加上它就可以使用$符号 <script>$("h1").css("color","red") </script> </body> </html>
settings
""" Django settings for mysite01 project.Generated by 'django-admin startproject' using Django 1.11.3.For more information on this file, see https://docs.djangoproject.com/en/1.11/topics/settings/For the full list of settings and their values, see https://docs.djangoproject.com/en/1.11/ref/settings/ """import os# Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '^e05n!#hnt0$l_haxv9f^d)5k$e--b6nn3&)iubu2f$e+p12r^'# SECURITY WARNING: don't run with debug turned on in production! DEBUG = TrueALLOWED_HOSTS = []# Application definition INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','blog.apps.BlogConfig', ]MIDDLEWARE = ['django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware',#'django.middleware.csrf.CsrfViewMiddleware',#当html页面使用post方法此中间件必须注释,否则,forbbden'django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware', ]ROOT_URLCONF = 'mysite01.urls'TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [os.path.join(BASE_DIR, 'templates')],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},}, ]WSGI_APPLICATION = 'mysite01.wsgi.application'# Database # https://docs.djangoproject.com/en/1.11/ref/settings/#databases DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3','NAME': os.path.join(BASE_DIR, 'db.sqlite3'),} }# Password validation # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',},{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',},{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',},{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',}, ]# Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us'TIME_ZONE = 'UTC'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/' # 要想哪static文件夹内容,用/static/这一串来拿,参考index页面引方式,其实这是别名,以后都用别名 STATICFILES_DIRS = (# 必须加os.path.join(BASE_DIR, 'blog/static'),# 路劲拼接,base相当于在mysite这一层,即最外层,按这个路径往下找static.逗号必须加,少了不能执行 )
转载于:https://www.cnblogs.com/wfl9310/p/9401602.html
显示年月,注册页面和后台数据交互,不涉及数据库相关推荐
- servlet向ajax传递数据库,一、JSP、servlet、SQL三者之间的数据传递(前台与后台数据交互)...
背景: 目前业界很流行的MVC(model-view-control)开发模式,理解为 模型是Bean, 视图是 Html/Jsp, 控制是Servlet, 关联数据库的Dao web的运行机制: 数 ...
- 实现小程序与SSM后台数据交互
实现小程序与SSM后台数据交互 项目源码 文章目录 实现小程序与SSM后台数据交互 项目源码 1.controller 2.小程序js 实现效果 1.controller @RequestMappin ...
- --@angularJS--自定义服务与后台数据交互小实例
1.myService.html: <!DOCTYPE HTML> <html ng-app="app"> <head> <tit ...
- ajax与后台php,怎么在thinkPHP5中使用ajax实现与后台数据交互
怎么在thinkPHP5中使用ajax实现与后台数据交互 发布时间:2021-03-20 17:20:01 来源:亿速云 阅读:87 作者:Leah 这篇文章给大家介绍怎么在thinkPHP5中使用a ...
- 微信小程序数据库交互 php,微信小程序wx.request实现后台数据交互功能分析
本文主要介绍微信小程序wx.request实现后台数据交互功能,分析微信小程序wx.request在后台数据交互过程中遇到的问题与相关的解决方法,需要的朋友可以参考下 记录微信小程序wx.reques ...
- web前端与后台数据交互
1.前端请求数据URL由谁来写? 在开发中,URL主要是由后台来写的,写好了给前端开发者.如果后台在查询数据,需要借助查询条件才能查询到前端需要的数据时,这时后台会要求前端提供相关的查询参数,这里的查 ...
- 登录、注册页面及后台代码
一.登录页面及后台代码 1.登录页面如图1所示 首先进行身份选择,由"管理员"和"用户"两种身份进行选择,选择不同的身份,程序会进入不同的数据表检索登录信息:当 ...
- 小程序后台数据交互-个人中心
目录 一,获取用户昵称和头像 登录过程 二,登录-小程序 三,后台 小程序服器配置 一,获取用户昵称和头像 登录过程 小程序登录 小程序可以通过微信官方提供的登录能力方便地获取微信提供的用户身份标识, ...
- js前台与后台数据交互-前台调后台
网站是围绕数据库来编程的,以数据库中的数据为中心,通过后台来操作这些数据,然后将数据传给前台来显示出来(当然可以将后台代码嵌入到前台).即: 下面就讲前台与后台进行数据交互的方法,分前台调用后台方 ...
最新文章
- ubuntu中安装rabbitmq
- java io 网络编程_[笔面] Java IO和网络编程相关面试
- 解决 win10 下载文件到某盘 没有权限
- RocketMQ源码分析之RocketMQ事务消息实现原下篇(事务提交或回滚)
- 用fft对信号进行频谱分析实验报告_FFT分析频谱无泄露的条件
- 基于Spring Boot的“课程设计”的设计与实现
- 一门从业4年都没能用上的优化技术
- 使用Pytorch简单实现混合密度网络(Mixture Density Network, MDN)
- python垃圾分类图像识别算法_用算法帮上海大妈垃圾分类,扔错罚款!长点心吧你...
- 前景检测算法(十六)--背景减除结束篇
- java-日记本(一)
- svchost.exe进程内存占用过高案例解决方案一例
- python代码错误有哪些_Python常见十六个错误集合,你知道那些?
- Relative Orientation 与fundamental essential matrix
- 超详细dns劫持解决办法分享
- 2021年中国鸡尾酒杯市场趋势报告、技术动态创新及2027年市场预测
- MAC电脑 系统 恢复出厂设置
- Cadence OrCAD Capture 四种定位到图纸指定位置的方法说明
- php页眉,FPDF页眉和页脚 - php
- 请问网页的在线聊天怎么实现