小编Sty*_*leZ的帖子

“用户=认证(请求,用户名=用户名,密码=密码)”用户是无

def login_page(request):
    form = LoginForm(request.POST or None)
    context = {
        "form": form
    }
    print("User logged in")
    #print(request.user.is_authenticated())
    if form.is_valid():
        print(form.cleaned_data)
        username  = form.cleaned_data.get("username")
        password  = form.cleaned_data.get("password")
        user = authenticate(request, username=username, password=password)
        print(user)
        print(request.user.is_authenticated())
        if user is not None:
            print(request.user.is_authenticated())
            login(request, user)
            # Redirect to a success page.
            context['form'] = LoginForm()
            return redirect("/")
        else:
            # Return an 'invalid login' error message.
            print("Error")

    return render(request, "auth/login.html", context)
Run Code Online (Sandbox Code Playgroud)

你好,我已经开始在 Django 中玩了,但是在一个教程中,当导师点击提交时,它会验证用户......我已经发现堆栈溢出几乎相同的问题,但问题是,一个人有一个字符串变量( username = 'username' )但问题是当我单击提交时出现错误:

User logged in
{'username': 'test123', 'password': 'test'}
None …
Run Code Online (Sandbox Code Playgroud)

authentication django python-3.x form-authentication

5
推荐指数
1
解决办法
1190
查看次数

我想在 Flask 中制作漂亮的 JSON 格式

我想在我的 Flask 网站(API 网站)上输出一个漂亮的 JSON,但我的 JSON 文件不想正确格式化。

我尝试了多种方法:

return json.loads(json.dumps(json_text, indent=4))
return json.dumps(json_text, indent=4)
return jsonify(json_text)
Run Code Online (Sandbox Code Playgroud)

json_it() 函数:

def json_it(self):
    input_part = {"amount": self.amount, "currency": str(self.input_currency)}
    output_part = self.result
    return {"input": input_part, "output": output_part}
Run Code Online (Sandbox Code Playgroud)

烧瓶API代码:

converter = CurrencyConvert(float(amount), input_currency, output_currency)
json_text = converter.json_it()
the_output = json.dumps(json_text, indent=10)
print(the_output)
return the_output, 200
Run Code Online (Sandbox Code Playgroud)

CurrencyConvert 正在使用这 3 个参数,并根据它制作字典,正如您在打印它的输出中看到的那样。(那个应该不是问题)

输出(API):如果我打印它:

{
          "input": {
                    "amount": 10.92,
                    "currency": "GBP"
          },
          "output": {
                    "AED": 46.023890640000005,
          }
}
Run Code Online (Sandbox Code Playgroud)

如果我退货:

{ "input": { "amount": 10.92, "currency": "GBP" },"output": {"AED": …
Run Code Online (Sandbox Code Playgroud)

python json flask

5
推荐指数
1
解决办法
7039
查看次数

无法找到或访问本地目录中的文件

当我尝试从本地目录复制到远程目录时,我的项目出现错误

错误信息:

fatal: [xxx]: FAILED! => {
"changed": false, "msg": "could not find 
src=/Users/xxx/Desktop/Docker/The_Task/./roles/docker_registry/templates,
Could not find or access 
'/Users/xxx/Desktop/Docker/The_Task/./roles/docker_registry/templates' 
on the Ansible Controller.\n
If you are using a module and expect the file to exist on the remote, see the remote_src option"
}
Run Code Online (Sandbox Code Playgroud)

剧本.yml

- name: Copying required files
  template:
    src: ./roles/docker_registry/templates
    dest: /tmp/docker_registry
Run Code Online (Sandbox Code Playgroud)

如果我做:

cd /Users/xxx/Desktop/Docker/The_Task/./roles/docker_registry/templates
Run Code Online (Sandbox Code Playgroud)

它将目录更改为我想要的目录...错误似乎来自ansible端。(它不适用于绝对路径八)

如果我使用默认的复制模块,那么它工作得很好

- name: copy files [local -> remote]
  copy:
    src: ./roles/docker_registry/templates
    dest: /tmp/docker_registry
Run Code Online (Sandbox Code Playgroud)

知道我应该做什么才能让它发挥作用吗?[其从本地复制 -> 远程 ]


但我仍然无法将整个目录复制到远程计算机中

ansible ansible-template

5
推荐指数
1
解决办法
5万
查看次数

当它不是无头时,Selenium 不会截取整个网站的屏幕截图

免责声明:我知道,已经有一个类似的问题了,但是没有一个答案适用于无头浏览器,所以我决定制作一个更详细的问题(我提到的问题:用带有 chromedriver 的 Selenium Python

大家好。

我偶然发现了一个看起来很简单但很难解决的问题。我需要在显示器上截取非无头浏览器的屏幕截图,即 1920x1080(稍后会很重要),这将截取整个网页的屏幕截图,而不仅仅是您当前可以看到的部分。

我尝试过什么:

import os
import time

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument("--start-maximized")
chromedriver = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'chromedriver.exe')
chrome = webdriver.Chrome(chromedriver, options=chrome_options)

url = 'https://stackoverflow.com/'

chrome.get(url)
time.sleep(2)

total_height = chrome.execute_script("return document.body.parentNode.scrollHeight") + 1000

chrome.set_window_size(1920, total_height)

time.sleep(2)
chrome.save_screenshot("screenshot1.png")
chrome.quit()
Run Code Online (Sandbox Code Playgroud)

^ 这个,无头工作得很好,不幸的是,当我删除该--headless选项时,selenium 会尝试调整自身大小,但由于它试图调整到1080height显示器)上方的大小,因此它立即调整为1080导致屏幕截图的大小1920x1080。我需要的“理论”方式是让硒headless仅在截取屏幕截图时暂时运行(不幸的是,据我所知,这是不可能的)。

其他在浏览器非无头时不起作用的常用方法:

el = driver.find_element_by_tag_name('body')
el.screenshot(path)
Run Code Online (Sandbox Code Playgroud)
original_size = driver.get_window_size()
required_width = driver.execute_script('return document.body.parentNode.scrollWidth')
required_height = driver.execute_script('return document.body.parentNode.scrollHeight')
driver.set_window_size(required_width, …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver selenium-webdriver

3
推荐指数
1
解决办法
3050
查看次数