Django Fortune Teller Tuple

good day ! currently im stuck at step 15. There’s a message " AttributeError at /‘tuple’ object has no attribute ‘get’"

here’s my view and urls

from django.shortcuts import render # Create your views here. def fortune(request): return (request, "randomfortune/fortune.html")
from django.urls import path from . import views urlpatterns = [ path("", views.fortune) ]
from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path("", include("randomfortune.urls")) ]

Been stuck here for few days and looking forward for the guidance ! thanks alot

1 Like

Hi! I am new to Python and Django but I was stuck with this error as well and just found the solution so I figured I’d share what I found and where I found the explanation.

Your return function needs to use the render function for django to generate an HTTP response. Your code should read:

from django.shortcuts import render

.# Create your views here.
def fortune(request):
return render(request, “randomfortune/fortune.html”)

Ignore the period before the #, I had to add it to stop it from formatting that line as a heading.

Here is where I found an explanation for what the render function does: python - How does "return render(request, 'path/path')" works in Django? - Stack Overflow

I hope that helps!

2 Likes

thanks !! it’s working now !!! been stuck here for so many days…really appreciate it :smile:

1 Like

Thanks, it worked!

I forgot toput render in fortuneteller/views.py.

From this:

from django.shortcuts import render

def fortune(request):
return(request, “randomfortune/fortune.html”)

To This:

from django.shortcuts import render

def fortune(request):
return render(request, “randomfortune/fortune.html”)