2

What are the best method to have this url structure namedomain.com/ instead of namedomain.com/catalogue for Django Oscar.

Do I have to create new app call frontpage or can I edit the myshop/urls.py such as this line?

 path('', include(apps.get_app_config('oscar').urls[0])),

1 Answers1

2

You would need to customize the app config used for Oscar to modify it's urls as shown in How to add views or change URLs or permissions [Oscar Docs]. Firstly inherit from oscar.config.Shop in some suitable file of yours and override its get_urls method. You can simply copy the urls from its source code [GitHub] or even simply remove the first two urls using list slicing and add your own in their place:

from django.urls import path, reverse_lazy

from oscar import config


class MyShop(config.Shop):
    # Override get_urls method
    def get_urls(self):
        from django.contrib.auth import views as auth_views
        
        from oscar.views.decorators import login_forbidden
        
        urls = [
            # Removed the redirect
            path('', self.catalogue_app.urls), # modify this pattern so it is the homepage
            path('basket/', self.basket_app.urls),
            path('checkout/', self.checkout_app.urls),
            path('accounts/', self.customer_app.urls),
            path('search/', self.search_app.urls),
            path('dashboard/', self.dashboard_app.urls),
            path('offers/', self.offer_app.urls),

            # Password reset - as we're using Django's default view functions,
            # we can't namespace these urls as that prevents
            # the reverse function from working.
            path('password-reset/',
                login_forbidden(
                    auth_views.PasswordResetView.as_view(
                        form_class=self.password_reset_form,
                        success_url=reverse_lazy('password-reset-done'),
                        template_name='oscar/registration/password_reset_form.html'
                    )
                ),
                name='password-reset'),
            path('password-reset/done/',
                login_forbidden(auth_views.PasswordResetDoneView.as_view(
                    template_name='oscar/registration/password_reset_done.html'
                )),
                name='password-reset-done'),
            path('password-reset/confirm/<str:uidb64>/<str:token>/',
                login_forbidden(
                    auth_views.PasswordResetConfirmView.as_view(
                        form_class=self.set_password_form,
                        success_url=reverse_lazy('password-reset-complete'),
                        template_name='oscar/registration/password_reset_confirm.html'
                    )
                ),
                name='password-reset-confirm'),
            path('password-reset/complete/',
                login_forbidden(auth_views.PasswordResetCompleteView.as_view(
                    template_name='oscar/registration/password_reset_complete.html'
                )),
                name='password-reset-complete'),
        ]
        return urls

Next in your INSTALLED_APPS where you have oscar.config.Shop replace it with this custom app config:

INSTALLED_APPS = [
    ...
    'oscar.config.Shop', # Remove this
    'path.to.MyShop', # Add this
    ...
]
Abdul Aziz Barkat
  • 19,475
  • 3
  • 20
  • 33
  • Thank you for the provided solution and I've followed the instruction you provided to be working as I wanted. Many thanks. William – William Jerome Jun 13 '21 at 22:15