Skip to content

Instantly share code, notes, and snippets.

@ryu22e
Created July 24, 2019 14:33
Show Gist options
  • Save ryu22e/b07eccd85eb75e5be7abec0c72e83772 to your computer and use it in GitHub Desktop.
Save ryu22e/b07eccd85eb75e5be7abec0c72e83772 to your computer and use it in GitHub Desktop.
[WIP]Django path関数を使ったURL定義のやり方(1)
from django.db import models
class Book(models.Model):
title = models.CharField(max_length=50, verbose_name="タイトル")
"""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),
]
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'),
]
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