Okay so I looked through a few different slack posts on this ValueError, but it seemed most of them had to do with not returning render which it seems like I am doing that correct..?
I am sure it has to do with my if statements, just not sure what exactly or how to set the code up correctly so I can check the form request to the browser.
Edit: Following comments I took the is_valid check out for now just to see if I could get a new error, and it seems I am getting a name error. " name 'name' is not defined "
So it's not able to get the form users input into the api.
views.py:
from http.client import responses
from django.shortcuts import render
from .forms import SearchUser
from .search import search
def home(request):
if request.method == "POST":
form = SearchUser(request.POST)
form.cleaned_data["name"]
else:
return render(request, "main/home.html", {
'form': SearchUser(), # Reference to form
'userid': search(request),
# 'mmr':NA,
})
search.py:
import requests
def search(request):
data = requests.get(
f"https://americas.api.riotgames.com/riot/account/v1/accounts/by-riot-id/{name}/NA1?api_key=RGAPI-d1224a2c-9130-45ff-8c05-0656d56d105f")
return data.json()['puuid']
urls.py:
from django.urls import path
from . import views
urlpatterns = [
path("", views.home, name=""),
#path("", views.search, name=""),
]
home.html:
{% extends 'main/base.html'%}
{% block content %}
<h2>Valorant Ranked Checker</h2>
<form method="post" action="">
{% csrf_token %}
{{form}}
<button type="submit" name="search">
Get rank
</button>
</form>
<p><strong>{{userid}} - {{mmr}}</strong></p>
{% endblock %}
forms.py:
from django import forms
class SearchUser(forms.Form):
name = forms.CharField(label="Name", max_length=200)