Help us understand the problem. What is going on with this article?

djangoで複数アプリがある状態で同一htmlファイルが上手く読み込めない

起きている問題: 違うアプリのhtmlファイルが読み込まれる。

例:) test1とtest2というアプリを作成している。
    test2のディレクトリのindex.htmlを読みたいがtest1ディレクトリのindex.htmlに遷移してしまう。

解決方法


プロジェクトのurls.pyを改修
  urlpatterns = [
path('admin/', admin.site.urls),
path('test1/', include(('test1.urls', 'test1'),)),
path('test2/', include(('test2.urls', 'test2'),)),
]
includeを変更する。
include(('アプリ名.urls', 'アプリ名'),))
以上で上手く表示される。


※補足
htmlファイルでurlタグ{% url 'view関数' %}をこのように利用した場合はエラーを吐く。
なので、{% url 'アプリ名:view関数' %}に変更する事により吐かなくなる。

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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした