后台向前端页面传输数据
在html中用{
{data1}} {
{data2}}
在view中用:return render(request, ‘index.html’,{“data1”:dt01,“data2”:dt02})
from django.shortcuts import render
def main_page(request):
list = [‘view’, ‘Json’, ‘JS’]
return render(request, ‘index.html’, {
‘List’: json.dumps(list),
})----js----var List = {
{ List|safe }};
前台向后台传数据
在html中
在view.py中 def acount(request): username = 0 usertel = 0 usercity = 0 useraddress = 0 if request.method == "POST": username = request.POST.get("uname",None) usertel = request.POST.get("utel",None) usercity = request.POST.get("ucity",None) useraddress = request.POST.get("uadr",None) print(username) print(usertel) print(usercity) print(useraddress) response = HttpResponseRedirect('/index/') return response return render(request, 'acount.html')网络爬虫自动登录
from app01 import es_pachong
def es(request):
if request.method == “GET”:
es_pachong.espc()
print(“denglu”)
response = HttpResponseRedirect(‘http://cloud.izenery.com:8080/ideer/page/index.do’)
return response
return render(request, ‘es.html’)
########################################################################
from selenium import webdriver
def espc():
# 实例化出一个Firefox浏览器
driver = webdriver.Chrome()
driver.set_page_load_timeout(10)
driver.set_script_timeout(10)
# 设置浏览器窗口的位置和大小
driver.set_window_position(10, 10)
driver.set_window_size(200, 200)
# 打开一个页面(合天登录页)
try:
driver.get(“http://cloud.izenery.com:8080/ideer/”)
except:
print(“加载页面太慢,停止加载,继续下一步操作”)
driver.execute_script(“window.stop()”)
# 通过使用选择器选择元素进行模拟输入和点击按钮提交
driver.find_element_by_id(‘username’).clear()
driver.find_element_by_id(‘username’).send_keys(“15101092397”)
driver.find_element_by_id(‘pwd’).clear()
driver.find_element_by_id(‘pwd’).send_keys(“123456”)
driver.find_element_by_xpath(".//*[@class=‘col-lg-12’]/button").click()
测试数据的生成,类的建立
import numpy
import threading
import random
#Create your models here.
class login():
user01 = ((‘kdkj’,‘123456’),(1,1,1,0,0),(1,1,1,1,1,1,1,1,1))
user02 = ((‘shzf’, ‘shzf’), (1, 1, 0, 0, 0), (1, 1, 1, 0, 0, 0, 1, 0, 0)) ###eb\pd\ac\gl\pv\es\tf\dd
def str(self):
return self.ID
class data_static():
num_pro = 4
num_pd = 2
num_es = 1
num_pv = 1
num_ac = 1
num_gl = 0
def e_use(self):
e_u = random.randint(60, 80)
return e_u
def e_rate(self):
e_r = random.randint(0, 30)
return e_r
def alarm(self):
alm = random.randint(0, 10)
return alm
def alm_rate(self):
a_r = random.randint(-50, 50)
return a_r
def g_use(self):
g_