我目前正在開發一個項目,我想在其中構建一個可以輸入任何 URL 的網站。單擊按鈕,您應該會獲得所請求網站的屏幕截圖。此外,還有另一個按鈕可以將此 png 調制為 RGB 圖像。幾天來,我遇到了一個問題,屏幕截圖已生成,但不再顯示在我的網站上,而仍然顯示舊圖像。這是我的 HTML 模板。<h1> CovertCast </h1><form action="" method="post"> {% csrf_token %} <label>url: <input type="url" name="deine-url" value="https://"> </label> <button type="submit">Get Screenshot</button></form>{% load static %}<img src="/media/screenshot_image.png" class="bild"/><form action="/modulated.html" method="post"> {% csrf_token %} <button type="submit">Modulate</button></form><img src="/media/modulated_image.png" alt="abc"/>我的函數視圖如下所示:def screenshot(request): DRIVER = 'chromedriver.exe' if request.method == 'POST' and 'deine-url' in request.POST: url = request.POST.get('deine-url', '') if url is not None and url != '': options = webdriver.ChromeOptions() options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') driver = webdriver.Chrome(ChromeDriverManager().install()) driver.get(url) img_dir = settings.MEDIA_ROOT img_name = ''.join(['screenshot', '_image.png']) path = os.path.join(img_dir, img_name) if not os.path.exists(img_dir): os.makedirs(img_dir) driver.save_screenshot(path) screenshott = img_name driver.quit() return render(request, 'main.html') else: return render(request, 'main.html')def modulate(request):此外,我的應該調制 RGB 圖像的視圖在 Django 中根本不起作用,即使它在我單獨測試時有效。
添加回答
舉報
0/150
提交
取消