我目前正在使用一个应用程序(python / django / redis)来跟踪和注册农场中谷物的运动。
我的主应用程序运行正常,我现在正在尝试使我的最后一页正常工作。
该页面的目标是让用户在访问网络时将其加载到其“三星”选项卡上,然后进入该字段以收集一些要在localStorage中注册的数据。
完成操作后,他将返回网络并按加载按钮。按下按钮后,它将发送一个发布请求,告诉视图它需要从localStorage收集数据并将其放入Redis键。
这是视图的代码:
def creationField(request):
if request.method == 'POST':
driver = webdriver.Chrome()
url='XXX.X.X.XX:XXXX/XXXXXXX/XXXXXXX'
driver.get(url)
storage = LocalStorage(driver)
for i in range(1,50) :
keyCubage = 'Wagon_'+ str(i) + '_cubageWagon'
keyLimite = 'Wagon_'+ str(i) + '_limiteWagon'
keyCiterne = 'Wagon_'+ str(i) + '_numCiterne'
keyPBM = 'Wagon_'+ str(i) + '_pbmWagon'
keyTar = 'Wagon_'+ str(i) + '_tarWagon'
cubageWagon = storage.get(keyCubage)
limiteWagon = storage.get(keyLimite)
numCiterne = storage.get(keyCiterne)
pbmWagon = storage.get(keyPBM)
tarWagon = storage.get(keyTar)
if (cubageWagon == None or limiteWagon == None or numCiterne == None or pbmWagon == None or tarWagon == None):
result = "Break"
break
else:
result = "REDIS WORK"
r = redis.StrictRedis(host=settings.REDIS_AD, port=settings.REDIS_PORT, db='14')
key = 'Wagon_' + str(i)
r.hmset(key, {'Cubage': cubageWagon, 'limite': limiteWagon, 'numCiterne': numCiterne, 'pbmWagon': pbmWagon, 'tarWagon': tarWagon})
return render(request, 'creationField.html', locals())
LocalStorage类:
class LocalStorage:
def __init__(self, driver) :
self.driver = driver
def __len__(self):
return self.driver.execute_script("return window.localStorage.length;")
def items(self) :
return self.driver.execute_script( \
"var ls = window.localStorage, items = {}; " \
"for (var i = 0, k; i < ls.length; ++i) " \
" items[k = ls.key(i)] = ls.getItem(k); " \
"return items; ")
def keys(self) :
return self.driver.execute_script( \
"var ls = window.localStorage, keys = []; " \
"for (var i = 0; i < ls.length; ++i) " \
" keys[i] = ls.key(i); " \
"return keys; ")
def get(self, key):
return self.driver.execute_script("return window.localStorage.getItem(arguments[0]);", key)
def set(self, key, value):
self.driver.execute_script("window.localStorage.setItem(arguments[0], arguments[1]);", key, value)
def has(self, key):
return key in self.keys()
def remove(self, key):
self.driver.execute_script("window.localStorage.removeItem(arguments[0]);", key)
def clear(self):
self.driver.execute_script("window.localStorage.clear();")
def __getitem__(self, key) :
value = self.get(key)
if value is None :
raise KeyError(key)
return value
def __setitem__(self, key, value):
self.set(key, value)
def __contains__(self, key):
return key in self.keys()
def __iter__(self):
return self.items().__iter__()
def __repr__(self):
return self.items().__str__()
我很肯定本地存储不是问题,我能够从一些js尝试的内容中进行写入/读取。
我当前的问题是,当我按下加载按钮并将帖子发送给我时,页面崩溃并出现以下错误:
Message: unknown error : unhandled inspector error:{"Code":"-32000", "message","Cannot navigate to invalid URL"}
如果我复制粘贴似乎对他无效的网址,则会加载该文件而不会出现问题,因此我不确定是什么使该网址对他无效?
答案 0 :(得分:0)
如果您说您的网址是有效的,并且收到了无效的网址消息,请尝试以下操作: 尝试将网址存储到String literals(用r'标记)
url = r'url_path_goes_here'