python - 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。
我怎样才能做到这一点?
解决方案
根据您更准确地想要的内容,您可以:
- 在您的 virtualHost 设置中的 Apache 级别重定向,
- 在您的模板中指定指向一个或另一个域的链接
在您的 view.py 中,指定指向另一个 URL 的重定向
推荐阅读
- python - 如何在张量流中将序列映射到序列?
- node.js - 如何挂钩节点http请求?
- ios - 重定向到 AppDelegate 时可选值的堆栈跟踪或崩溃点
- android - 在我的 react native 项目中使用原生基础的 Button 组件,它在 android 文本中产生问题
- prolog - 如何让 SWI-Prolog 在交互模式下始终打印带引号的字符串
- mongodb-query - 如何在MongoDB中实现follow RMDB查询
- mysql - Mysql 删除后自增
- spring-boot - 春天云数据流自定义应用程序配置传递环境变量
- reactjs - 如何在反应中循环状态
- c# - 无法在 UAT 服务器中将数据发布到 Salesforce