首页 > 解决方案 > Django中不同应用程序的不同网址

问题描述

我的 Django 项目文件夹中有两个应用程序,我希望每个 urls.py 文件指向不同的域。例如:

我的第一个项目 urls.py 文件如下所示:

urlpatterns = [
path('register/', views.register, name='register'),
# path('login/', LoginView.as_view(template_name='Clientes/login.html'), name='login'),
path('login/', views.login_view, name='login'),
path('', views.login_view, name='login'),
path('mail/', views.mail, name='mail'),
path('profile/config', views.config_view, name="config"),
path('profile/dashboard', views.dashboard_view, name="dashboard"),
path('profile/terms', views.TermsView.as_view(), name="terms"),
path('profile/distribution', views.DistributionView.as_view(), name="distribution"),
# path('', LoginView.as_view(template_name='Clientes/login.html'), name='index'),
path('profile/order', views.OrderView.as_view(), name='order'),
path('profile/list/<pk>', views.detail_view, name='detail_view'),
path('profile/list/', views.ListOperationsView.as_view(), name='list_operations'),

path('reset-password/', PasswordResetView.as_view(), name="reset_password"),
path('reset-password/done/', PasswordResetDoneView.as_view(), name="password_reset_done"),
path('reset-password/confirm/', PasswordResetConfirmView.as_view(), name="password_reset_confirm"),

path('profile/logout/', views.logout_view, name='logout'),
path('profile/', views.ProfileView.as_view(), name='profile'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我希望该应用程序指向 example1.com。

我的第二个应用程序 urls.py 文件如下所示:

urlpatterns = [
path('atendimento/', views.DataView.as_view(), name='user_view'),
path('atendimento/opções', views.redirect_view, name='redirect_view'),
path('atendimento/rastreio', views.track_view, name='track_view'),
path('atendimento/trocas', views.change_view, name='change_view'),
path('atendimento/devolver', views.devolution_view, name='devolution_view'),
path('atendimento/contato', views.contact_view, name='contact_view'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT_ATENDIMENTO)

我希望这个应用程序指向 example2.com。

我怎样才能做到这一点?

标签: pythondjangoheroku

解决方案


根据您更准确地想要的内容,您可以:

  1. 在您的 virtualHost 设置中的 Apache 级别重定向,
  2. 在您的模板中指定指向一个或另一个域的链接
  3. 在您的 view.py 中,指定指向另一个 URL 的重定向

    否则这可能有用


推荐阅读