user9890549
user9890549

Reputation:

Django tutorial error part3

enter image description here I have a problem that I am working on Django tutorial and I want to take it in my browser at /polls/34/ but I don't know how to do that It will refuse from localhost when I try to put in browser

I use python3 and django 2.0

Django tutorial gave this Take a look in your browser, at “/polls/34/”. It’ll run the detail() method and display whatever ID you provide in the URL. Try “/polls/34/results/” and “/polls/34/vote/” too – these will display the placeholder results and voting pages

but I can't load that

Please Suugests and check below code

mysite/urls.py

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

mysite/polls/urls.py

from django.urls import path

from . import views

urlpatterns = [
    # ex: /polls/
    path('', views.index, name='index'),
    # ex: /polls/5/
    path('<int:question_id>/', views.detail, name='detail'),
    # ex: /polls/5/results/
    path('<int:question_id>/results/', views.results, name='results'),
    # ex: /polls/5/vote/
    path('<int:question_id>/vote/', views.vote, name='vote'),
]

mysite/polls/views.py

from django.http import HttpResponse

def detail(request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

def results(request, question_id):
    response = "You're looking at the results of question %s."
    return HttpResponse(response % question_id)

def vote(request, question_id):
    return HttpResponse("You're voting on question %s." % question_id)

Upvotes: 0

Views: 1742

Answers (3)

rsb
rsb

Reputation: 383

In the URL you should give

http://127.0.0.1:8000/polls/1/

and the o/p visible is "You are looking at question 1."

or http://127.0.0.1:8000/polls/34/

and the o/p visible is "You are looking at question 34."

Upvotes: 0

Pradeep Kumar
Pradeep Kumar

Reputation: 92

Through the URL I see that you haven't mentioned your URL properly. When you start your server through your command prompt with python manage.py runserver you could see a few series of output statements one of them is your starting development server at http://127.0.0.1:8000/ to that you add your intended URL in your case should be http://127.0.0.1:8000/polls/34/ will run you method you have connected to.

Note: In your case, your internal server might be different.

Upvotes: 2

Druta Ruslan
Druta Ruslan

Reputation: 7412

in your picture you go to polls/34 but you need to type the address also if you do all right from django tutorial access

http://localhost:8000/polls/34/

Upvotes: 1

Related Questions