Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23276

Django views file says

$
0
0

So i have the folloing error: didn't return an HttpResponse object. It returned None instead.And from what I read it was due to to not having a render in the return line, however after checking multiple times, the render is being output from the return function as it did on the code that worked (the second part) I have double checked and it seems right, I also get the following errors from django:

\django\core\handlers\exception.py, line 55, in inner                response = get_response(request)                               ^^^^^^^^^^^^^^^^^^^^^ line 204, in _get_response        self.check_response(response, callback)line 332, in check_response            raise ValueError(
# Create your views here.def home(request):  #define a view, a home view that passes a request## goes to home html and passes in a dictionary later    import json    import requests    api_request = requests.get("https://www.airnowapi.org/"  # secret key erased)    try:        api = json.loads(api_request.content)    except Exception as e:        api = "Chiiispas, something went wrong"    if api[0]['Category']['Name'] == "Good":  ## sets a conditional when the output comes out and links it onto the corresponding html class        category_description = 'Esta con madre el clima y puedes hacer cosas chingonas'        category_color='Good'   # html classes are on the base html file    elif api[0]['Category']['Name'] == "Moderate":        category_description ='Cámara mi tibio, toma agua y ponte pilas para que no te me desmayes'        category_color='Moderate'    elif api[0]['Category']['Name'] == "USG":            category_description ='Anda de viva la contaminación, pero no te dejes mi tibio'            category_color='USG'    elif api[0]['Category']['Name'] == "Unhealthy":        category_description ='Se está poniendo al tiro el clima, tú sal con tapaocicos y ya andas gucci'        category_color='Unhealthy'    elif api[0]['Category']['Name'] == "Very Unhealthy":        category_description ='Estos niveles de contaminación  son generados por los neoliberales '        category_color='Very Unhealthy'    elif api[0]['Category']['Name'] == "Hazardous":        category_description ='no es por alarmarte pero mejor vete del país que anda insano en clima'        category_color=''        return render(request,'home.html',{'api': api,"category_description":category_description,"category_color": category_color }) # passes the request into the functiondef about(request):     return render(request,'about.html',{}) 

this was the code that was previously working flawlessly but the fundamentals seem the same on the new file:

# Create your views here.def home(request):  #define a view, a home view that passes a request    import json    import requests    api_request = requests.get("https://www.airnowapi.org/aq/observation" )    try:        api = json.loads(api_request.content)    except Exception as e:        api = "Chiiispas, something went wrong"    return render(request,'home.html',{'api':api})  # passes the request into the function## goes to home html and passes in a dictionary laterdef about(request):     return render(request,'about.html',{}) ```

Viewing all articles
Browse latest Browse all 23276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>