19
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Django2.0以降の変更点で気づいたポイント:path設定 "path"を使ったinclude

Last updated at Posted at 2018-01-19

###転載元ブログ情報

この記事は自分のブログの転載です。是非遊びに来てください〜

#本編

###エラーが出たところから報告
もしかしたら、Django2系特有じゃないかもしれないのですが、Django2系扱って「あれ?」と思ったところが同じ人には役立つかもです^^ とりあえず下記は通った設定です。

###変更点:urls.pyのパスの指定の仕方が変わった"path"を使ったinclude

Django1.8
settings.pyのあるディレクトリのurls.py

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('<アプリ名>.urls', namespace='<アプリ名>')),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Django2.0

settings.pyのあるディレクトリのurls.py

from django.contrib import admin
from django.urls import include, path
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('<アプリ名>.urls')),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Django1系と2系でpathという新しい指定の仕方が登場しています。includeとpathの組み合わせは上記でエラーなく行けました。一方でstaticファイルの指定方法は一緒でした。

###参考記事
https://docs.djangoproject.com/en/2.0/releases/2.0/

19
17
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?