Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

【作成中】DjangoでWebアプリケーションを作ってみる

More than 1 year has passed since last update.

これに沿って作ってみる。
https://eiry.bitbucket.io/index.html

詰まったところ

Django アプリケーションを作ろう

https://eiry.bitbucket.io/tutorials/tutorial/application.html#django

mysiteフォルダーの中にhelloフォルダーが作られます。

そうならなかったので、手動で「hello」フォルダをmysite配下に移動した。

ビュー関数とURLConfを書こう

https://eiry.bitbucket.io/tutorials/tutorial/views_and_urls.html#urlconf

hello.urls.pyの編集内容

サイトの通り実装すると次のエラーが発生する。

File "/Users/****/PycharmProjects/practice/mysite/mysite/urls.py", line 22, in <module>
    url(r'^hello/', include('hello.urls', namespace='hello')),
  File "/Users/****/wk_yuta/PycharmProjects/practice/venv/lib/python3.7/site-packages/django/urls/conf.py", line 39, in include
    'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.

これを解消するため、app_nameを記述する。

from django.conf.urls import url
from . import views

# このapp_nameを追加する
app_name = "hello"

urlpatterns = [
    url(r'^$', views.hello_world, name='hello_world'),
]

参考:https://teratail.com/questions/88819

Maruo110
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away