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 \ \ \ \ \测试\ \ \ \{{ hello }}\ \ \

相关推荐
q***649718 小时前
Spring Boot 各种事务操作实战(自动回滚、手动回滚、部分回滚)
java·数据库·spring boot
忘记92618 小时前
mybatis是什么
数据库·oracle·mybatis
q***925118 小时前
Springboot3 Mybatis-plus 3.5.9
数据库·oracle·mybatis
q***474319 小时前
PostgreSQL 中进行数据导入和导出
大数据·数据库·postgresql
傻啦嘿哟19 小时前
物流爬虫实战:某丰快递信息实时追踪技术全解析
java·开发语言·数据库
optimistic_chen19 小时前
【Redis 系列】Redis详解
linux·数据库·redis·缓存·xsheel
熊文豪19 小时前
17年稳定运行:金仓数据库如何成为电力行业的“数字基石“
数据库·kingbasees·金仓数据库·电科金仓·kes
r***113319 小时前
Redis--模糊查询--方法实例
数据库·redis·缓存
q***710120 小时前
SQL注入(SQL Injection)攻击原理与防御措施
数据库·sql·oracle
f***R820 小时前
解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException
java·数据库·sql