1

I have trouble getting the correct respond while I following the tutoriala link I can't get into the views whenever I run server. Please help me go through my code. I am not sure is it the problem with the version of django that I'm using and the one the tutorial is using because I notice the one in the tutorial using from django.urls import path but when I start an app it comes with from django.conf.urls. There's the different and I'm confused.

Request Method: GET
Request URL: http://127.0.0.1:8000/polls/

Django Version: 1.11.6
Python Version: 3.6.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "c:\users\CaddyKKhaw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py" in inner 41.             response = get_response(request)
File "c:\users\Caddy KKhaw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py" in __call__ 142.             response = 
self.process_response(request, response)
File "c:\users\Caddy KKhaw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\middleware\clickjacking.py" in process_response 32.         if response.get('X-Frame-Options') is not 
None:
Exception Type: AttributeError at /polls/
Exception Value: 'tuple' object has no attribute 'get'

Here's my polls/views.py

from django.http import HttpResponse

def index(request):
    return HttpResponse("You did it this time!,"),

Here's my polls/urls.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url('', views.index, name="index")

]

here's my mysite/urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^polls/', include("polls.urls")),
    url(r'^admin/', admin.site.urls),
]

1 Answer 1

10

You have an trailing comma left in your return statement in views. Remove that and you'll be fine.

To be precise, upadte the following line from

return HttpResponse("You did it this time!,"),

to

return HttpResponse("You did it this time!,")

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for helping me out. Its solved my stupid mistake. will be writing carefully next time.
Wow. Thank you for this. Solved a significant amount of headache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.