파이썬 Django 질문이욧!!!

조회수 306회
# index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="{%url 'index'%}" method="POST">
    {% csrf_token %}
    <label for="URL1">URL :</label>
    <input type="text" name="URL" value="asdf"><br>
    <input type="submit" value="전송">

    <label for="">{{name_prop}} :</label>
    <input type="text"><br>

    <input type="text"><br>
    <input type="text"><br>
    <input type="text"><br>
</form>
</body>
</html>
# views.py
from django.shortcuts import render
import requests
from bs4 import BeautifulSoup
from requests.exceptions import MissingSchema

# Create your views here.
def index(request):
    global http_post_request
    url = request.POST.get('URL')

    data = {'urname' : "1", 'update':'update'} #update 넣어줘야 되네;
    cookies={'login':'test%2Ftest'}
    http_post_request = requests.post(url, data=data, cookies=cookies)
    print(http_post_request.text)
# 오류 메시지
MissingSchema at /
Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 4.1.5
Exception Type: MissingSchema
Exception Value:    
Invalid URL 'None': No schema supplied. Perhaps you meant http://None?
Exception Location: C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py, line 390, in prepare_url
Raised during:  main.views.index
Python Executable:  C:\ProgramData\Anaconda3\python.exe
Python Version: 3.9.7

index.html에서 URL값을 입력해서 views.py로 이동하여 url 값을 넣어주고 http_post_request.txt 결과값을 확인하고 싶습니다.

그런데 url 값을 index.html에서 입력을 해주어야 view.py에서 실행이 될텐데

view.py가 그냥 바로 실행이 되어서 url값에 None이 뜨는거 같습니다.

이런 경우 어떻게 해야할까요?

  • urls.py는 어디있나요? 초보자 2023.1.24 11:23

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)