Created
July 24, 2019 14:33
-
-
Save ryu22e/b07eccd85eb75e5be7abec0c72e83772 to your computer and use it in GitHub Desktop.
[WIP]Django path関数を使ったURL定義のやり方(1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Book(models.Model): | |
title = models.CharField(max_length=50, verbose_name="タイトル") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""django_url_example URL Configuration | |
The `urlpatterns` list routes URLs to views. For more information please see: | |
https://docs.djangoproject.com/en/1.11/topics/http/urls/ | |
Examples: | |
Function views | |
1. Add an import: from my_app import views | |
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') | |
Class-based views | |
1. Add an import: from other_app.views import Home | |
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') | |
Including another URLconf | |
1. Import the include() function: from django.conf.urls import url, include | |
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) | |
""" | |
from django.conf.urls import url, include | |
from django.contrib import admin | |
urlpatterns = [ | |
url(r'^books/', include('books.urls', namespace='books')), | |
url(r'^admin/', admin.site.urls), | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import url | |
from . import views | |
urlpatterns = [ | |
url(r'^$', views.BookListView.as_view(), name='list'), | |
url(r'(?P<pk>\d+)/$', views.BookDetailView.as_view(), name='detail'), | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic.list import ListView | |
from django.views.generic.detail import DetailView | |
from .models import Book | |
class BookListView(ListView): | |
model = Book | |
template_name = 'books/list.html' | |
class BookDetailView(DetailView): | |
model = Book | |
template_name = 'books/detail.html' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment