python django mvc

MVC框架:

1、URL映射到方法

[root@zz mysite]# cat urls.py

"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:

https://docs.djangoproject.com/en/1.11/topics/http/urls/

Examples:

Function views

  1. Add an import: from my_app import views

  2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')

Class-based views

  1. Add an import: from other_app.views import Home

  2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')

Including another URLconf

  1. Import the include() function: from django.conf.urls import url, include

  2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))

"""

from django.conf.urls import url

from django.contrib import admin

from polls import views as polls_view

urlpatterns = [

url(r'^admin/', admin.site.urls),

url(r'^cmdb/add/$',polls_view.cmdb_add ),

url(r'runoob/', polls_view.runoob)

]

2、具体方法

[root@zz polls]# cat views.py

-*- coding: utf-8 -*-

from future import unicode_literals

from django.shortcuts import render

from django.http import HttpResponse

Create your views here.

from django.shortcuts import render,render_to_response,redirect

from django.http import HttpResponse, HttpResponseNotFound

import datetime

from django.views.decorators.http import require_http_methods,require_GET

from django.http import HttpResponseRedirect

from django.shortcuts import render

import os

import os

import json

from django.template import loader

Create your views here.

import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

from django.shortcuts import render

def runoob(request):

context = {}

context['hello'] = 'Hello World!'

return render(request, 'runoob.html', context)

3、

[root@zz mysite]# cat polls/templates/runoob.html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>测试</title>

</head>

<body>

<h1>{{ hello }}</h1>

</body>

</html>

相关推荐
Hacker_LaoYi1 小时前
【渗透技术总结】SQL手工注入总结
数据库·sql
岁月变迁呀1 小时前
Redis梳理
数据库·redis·缓存
独行soc1 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍06-基于子查询的SQL注入(Subquery-Based SQL Injection)
数据库·sql·安全·web安全·漏洞挖掘·hw
你的微笑,乱了夏天2 小时前
linux centos 7 安装 mongodb7
数据库·mongodb
工业甲酰苯胺2 小时前
分布式系统架构:服务容错
数据库·架构
独行soc3 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍08-基于时间延迟的SQL注入(Time-Based SQL Injection)
数据库·sql·安全·渗透测试·漏洞挖掘
White_Mountain3 小时前
在Ubuntu中配置mysql,并允许外部访问数据库
数据库·mysql·ubuntu
Code apprenticeship3 小时前
怎么利用Redis实现延时队列?
数据库·redis·缓存
百度智能云技术站3 小时前
广告投放系统成本降低 70%+,基于 Redis 容量型数据库 PegaDB 的方案设计和业务实践
数据库·redis·oracle
装不满的克莱因瓶3 小时前
【Redis经典面试题六】Redis的持久化机制是怎样的?
java·数据库·redis·持久化·aof·rdb