PHP速学视频免费教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
技术文章 > web前端 > Bootstrap教程
本篇文章手把手带大家使用django+bootstrap制作一个计算器,希望对大家有所帮助!
创建一个应用
添加应用到配置
创建一个html
编写视图函数
from django.shortcuts import render # Create your views here. def home(request): return render(request, 'index.html')
配置路由
from django.contrib import admin from django.urls import path,include from app.views import home urlpatterns = [ path('admin/', admin.site.urls), path('',home,name='hoome'), ]
下载地址https://github.com/twbs/bootstrap/releases/download/v3.4.1/bootstrap-3.4.1-dist.zip
将css、fonts、js复制到static文件夹下 没有则创建该文件夹。【相关推荐:《bootstrap教程》】
{% load static %} nbsp;html> <meta> <title>计算器</title> <link> <script></script> <script></script> <style> body{ background-position: center 0; background-repeat: no-repeat; background-attachment: fixed; background-size: cover; -webkit-background-size: cover; -o-background-size: cover; -moz-background-size: cover; -ms-background-size:cover; } .input_show{ margin-top: 35px; max-width: 280px; height: 35px; } .btn_num{ margin:1px 1px 1px 1px; width: 60px; } .btn_clear{ margin-left: 40px; margin-right: 20px; } .extenContent{ height: 300px; } </style><div> <div> <div> </div> <div> <input> <input> <br> <div> <button>7</button> <button>8</button> <button>9</button> <button>/</button> <br> <button>4</button> <button>5</button> <button>6</button> <button>*</button> <br> <button>1</button> <button>2</button> <button>3</button> <button>-</button> <br> <button>0</button> <button>00</button> <button>.</button> <button>+</button> </div> <div> <br> <button> 清空 </button> <button> 计算 </button> </div> </div> <div></div> </div> </div> <div></div> <script> var x=document.getElementById("txt_code"); var y=document.getElementById("txt_result"); function fun_7() { x.value+='7'; } function fun_8() { x.value+='8'; } function fun_9() { x.value+='9'; } function fun_div() { x.value+='/'; } function fun_4() { x.value+='4'; } function fun_5() { x.value+='5'; } function fun_6() { x.value+='6'; } function fun_mul() { x.value+='*'; } function fun_1() { x.value+='1'; } function fun_2() { x.value+='2'; } function fun_3() { x.value+='3'; } function fun_sub() { x.value+='-'; } function fun_0() { x.value+='0'; } function fun_00() { x.value+='00'; } function fun_dot() { x.value+='.'; } function fun_add() { x.value+='+'; } function fun_clear() { x.value=''; y.value=''; } </script><script> function ShowResult(data) { var y = document.getElementById('txt_result'); y.value = data['result']; } </script><script> $('#lgbut_compute').click(function () { $.ajax({ url:'compute/', type:'POST', data:{ 'code':$('#txt_code').val() }, dataType:'json', success:ShowResult }) }) </script>
import subprocess from django.http import JsonResponse from django.shortcuts import render # Create your views here. from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST def home(request): return render(request, 'index.html') @csrf_exempt def compute(request): code = request.POST.get('code') try: code = 'print(' + code + ')' result = subprocess.check_output(['python', '-c', code], universal_newlines=True, stderr=subprocess.STDOUT,timeout=30) except: result='输入错误' return JsonResponse(data={'result': result})
更多关于bootstrap的相关知识,可访问:bootstrap基础教程!!
已抢2128个
抢已抢2600个
抢已抢3108个
抢已抢4778个
抢已抢4185个
抢已抢34407个
抢