Skip to content

Commit

Permalink
polls questions
Browse files Browse the repository at this point in the history
  • Loading branch information
bmugwe committed May 25, 2022
1 parent 8c706c0 commit 89d2d48
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 7 deletions.
Binary file modified polls/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file modified polls/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified polls/__pycache__/views.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion polls/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

# Register your models here.
admin.site.register(Question)
admin.site.register(Choice)
admin.site.register(Choice )

3 changes: 3 additions & 0 deletions polls/templates/polls/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>

</html>
7 changes: 7 additions & 0 deletions polls/templates/polls/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>{{ question }}</h1>

<ul>
{% for choice in question.choice_set.all %}
<li>{{ choice.choice_text }}</li>
{% endfor %}
</ul>
11 changes: 11 additions & 0 deletions polls/templates/polls/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% if latest_question_list %}
<ol>
{% for question in latest_question_list %}
<li><a href=""{% url 'detail' question.id%}>
{{question.question_text}}
</a></li>
{% endfor %}
</ol>
{% else %}
<p>No polls available</p>
{% endif %}
1 change: 1 addition & 0 deletions polls/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.detail_1, name='detail'),
path('<int:question_id>/', views.detail, name='details'),
path('<int:question_id>/results/', views.results, name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
Expand Down
27 changes: 23 additions & 4 deletions polls/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from django.shortcuts import render
from django.http import HttpResponse
from asyncore import poll
from django.shortcuts import get_object_or_404, render
from django.http import Http404, HttpResponse, Http404
from django.template import loader

from polls.models import Question, Choice

# Create your views here.
def index(request):
return HttpResponse("<h1>Hello, world You're at the polls index.</h1>")
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 results(request, question_id):
response = "you're looking at the results of question %s."
Expand All @@ -13,4 +24,12 @@ def vote(request, question_id):
return HttpResponse("You're voting on question %s." % question_id)

def detail(request, question_id):
return HttpResponse("You're looking at question %s." % question_id)
try:
question = Question.objects.get(pk=question_id)
except:
raise Http404('Question does not exist')
return render(request, 'polls/detail.html', {'question': question})

def detail_1(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})
Binary file modified pollske/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file modified pollske/__pycache__/urls.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion pollske/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand Down
2 changes: 1 addition & 1 deletion pollske/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


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

]

0 comments on commit 89d2d48

Please sign in to comment.