0

I have two apps in my Django project folder and I want to each urls.py file to point to a different domain. For example:

My first project urls.py file looks like this:

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)

I want that application to point to example1.com.

My second application urls.py file looks like this:

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)

And I want this application to point to example2.com.

How can I do that?

Matheus Sant'ana
  • 563
  • 2
  • 6
  • 23
  • 1
    Do these apps share a database? Do they need to be in the same project at all? – Daniel Roseman Nov 06 '18 at 16:30
  • They share the same database and they need to be in the same project. – Matheus Sant'ana Nov 06 '18 at 16:32
  • How are you routing in Heroku? I've never used Heroku but in Nginx you'd achieve this by setting up location blocks to route the apps where you want via a reverse proxy. Or do you actually want the resolved URL to be different? – Scott Skiles Nov 06 '18 at 16:33
  • I added app.scalestore.com.br to be my site, I can also use other domain to reach the same application, but what I need is to go to, for example, app.scalestore.com.br and display one app and if I go to store.scalestore.com.br I would display the second app. – Matheus Sant'ana Nov 06 '18 at 16:40

1 Answers1

1

Depending on what you more precisely want you might either :

  1. Redirect at the Apache level in your virtualHost settings,
  2. In your templates specify links toward the one or the other domain
  3. In your view.py, specify redirections toward another URL

    otherwise this might be useful

  • So Django sites is the key to this? – Matheus Sant'ana Nov 06 '18 at 16:38
  • I don't have enough information on your project to be certain of what you actually want. For instance, do you want each domain to serve the same project but you want some part of the project to be preferably served under a domain? – Can I play with Mathness Nov 06 '18 at 16:40
  • I just commented above, maybe that would clarify the problem. – Matheus Sant'ana Nov 06 '18 at 16:42
  • 1
    So I guess yes Django sites is a solution to this. Another (simpler if you don't care what the user actually sees in address bar is to redirect the one on the other and differentiate directly in url.py. Don't forget you can make url.py for each app and then include both url into a principal url.py possibly by prepending a "app1/" and an "app2") – Can I play with Mathness Nov 06 '18 at 16:59