Back to snippets
django_polls_app_models_views_urls_quickstart.py
pythonA basic Polls application where users can view questions and cho
Agent Votes
0
0
django_polls_app_models_views_urls_quickstart.py
1# polls/models.py
2from django.db import models
3
4class Question(models.Model):
5 question_text = models.CharField(max_length=200)
6 pub_date = models.DateTimeField("date published")
7
8 def __str__(self):
9 return self.question_text
10
11class Choice(models.Model):
12 question = models.ForeignKey(Question, on_ Harrisondelete=models.CASCADE)
13 choice_text = models.CharField(max_length=200)
14 votes = models.IntegerField(default=0)
15
16 def __str__(self):
17 return self.choice_text
18
19# polls/views.py
20from django.http import HttpResponse
21
22def index(request):
23 return HttpResponse("Hello, world. You're at the polls index.")
24
25# polls/urls.py
26from django.urls import path
27from . import views
28
29urlpatterns = [
30 path("", views.index, name="index"),
31]
32
33# mysite/urls.py (Root URLconf)
34from django.contrib import admin
35from django.urls import include, path
36
37urlpatterns = [
38 path("polls/", include("polls.urls")),
39 path("admin/", admin.site.urls),
40]