Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

在此处输入图片说明

when I do something in 'profile' page, the url is concatenated to the next of 'profile'.

(当我在“配置文件”页面中执行某项操作时,该URL将连接到“配置文件”的下一个目录。)

but I want to link to just 'signout'.

(但我只想链接到“退出”。)

not 'profile/signout'

(不是“个人资料/退出”)

在此处输入图片说明

this is my urls.py.

(这是我的urls.py。)

在此处输入图片说明

when ever I do something in 'profile'page, the href link is concatenated to 'profile'url.

(每当我在“个人资料”页面中执行某项操作时,href链接就会串联到“个人资料” URL中。)

在此处输入图片说明 this is href source.

(这是href来源。)

since this href source is header.html, this page is included another pages.

(由于此href来源是header.html,因此该页面包含其他页面。)

and in the other pages, it works well.

(在其他页面上,效果很好。)

only in profile page, the href url is concatenated to 'profile/1' url.

(仅在个人资料页面中,href网址被连接到“ profile / 1”网址。)

how can I fix it?

(我该如何解决?)

  ask by Jin-hyeong Ma translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
465 views
Welcome To Ask or Share your Answers For Others

1 Answer

1. Another urls file within the same app

(1.同一应用程序中的另一个URL文件)

You can do that by creating another app custom_urls.py file.

(您可以通过创建另一个应用程序custom_urls.py文件来实现。)

project/urls.py

(项目/ urls.py)

path('', include('app_name.custom_urls')),

The you create the custom_urls.py within the app directory, then create your urls and they will be without the app prefix.

(您可以在应用目录中创建custom_urls.py ,然后创建您的网址,这些网址将没有应用前缀。)

The problem is that reverse will not work for those urls, which is not good.

(问题在于, reverse不适用于这些网址,这不好。)

2. Create another app

(2.创建另一个应用)

That's simple, just python manage.py startapp app_name and configure everything as usual.

(这很简单,只需python manage.py startapp app_name并像往常一样配置所有内容。)

It's good if you need a lot of urls without a prefix.

(如果您需要很多没有前缀的URL,那就很好了。)

3. Put those urls without prefix in the project/urls.py

(3.将那些没有前缀的URL放入project/urls.py)

I think it's the best solution for this particular case.

(我认为这是针对此特定案例的最佳解决方案。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...