# Views.py and Urls.py not rendering properly

**URL:** <https://forum.djangoproject.com/t/views-py-and-urls-py-not-rendering-properly/5090>\
**Category:** Using Django\
**Created:** [November 4, 2020, 4:27pm UTC](https://forum.djangoproject.com/t/views-py-and-urls-py-not-rendering-properly/5090 "2020-11-04T16:27:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ninety5](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ninety5/32/2358_2.png) [@ninety5](https://forum.djangoproject.com/u/ninety5)\
**Post date:** [November 4, 2020, 4:27pm UTC](https://forum.djangoproject.com/t/views-py-and-urls-py-not-rendering-properly/5090/1 "2020-11-04T16:27:29Z")

</div>

Building your first Django app [Part 2](https://docs.djangoproject.com/en/3.0/intro/tutorial02/) has us add more views to our polls/views.py which takes a string specifier and replaces it with values from **question\_id** which is given to the function as a parametre.

The issue here is, I get the string as it is in views.py with the %s placeholder still there like so

# You are looking at the results of question %s

Below are my views and urls.py code snippet

# Views.py

```auto
from django.shortcuts import render
from django.http import HttpResponse
from .models import Question
from django.template import loader

def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    template = loader.get_template('polls/index.html')
    context = {
        'latest_question_list': latest_question_list,
    }
    return HttpResponse(template.render(context, request))

def detail(request, question_id):
    return HttpResponse("You are looking at %s ", question_id)

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

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

```

# Urls.py

```auto
from django.urls import path

from . import views

urlpatterns = [

    # ex: polls
    path('', views.index, name='index'),

    # ex: polls/5/detail
    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'),

```

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [November 4, 2020, 4:33pm UTC](https://forum.djangoproject.com/t/views-py-and-urls-py-not-rendering-properly/5090/2 "2020-11-04T16:33:37Z")

</div>

The issue is that you’re passing the value for [formatting string](https://python-reference.readthedocs.io/en/latest/docs/str/formatting.html) as an argument to HttpResponse. You need to do the following instead:

```
return HttpResponse("You are looking at %s " % question_id)

```

You can also use [template strings](https://docs.python.org/3/library/string.html#template-strings) with python 3.5+:

```
return HttpResponse(f"You are looking at {question_id}")
```

---

<div class="post-metadata">

**Author:** ![ninety5](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ninety5/32/2358_2.png) [@ninety5](https://forum.djangoproject.com/u/ninety5)\
**Post date:** [November 4, 2020, 5:32pm UTC](https://forum.djangoproject.com/t/views-py-and-urls-py-not-rendering-properly/5090/3 "2020-11-04T17:32:32Z")

</div>

Thanks for this, it was obviously an oversight because it (the percent sign) was added in the tutorial and I was just too carried away to have thought about it.
