如何向django-oscar添加新视图

问题描述 投票:0回答:1

我不认为我完全掌握了django-oscar的文档。我正在尝试添加一个新视图,即网站/的主视图。但是,无论我执行什么操作,当我要访问/catalogue/时,它始终会转到/

它说我应该做以下事情:

from oscar.apps.offer.apps import OfferConfig as CoreOfferConfig
from .views import IndexView
from django.conf.urls import url


class OfferConfig(CoreOfferConfig):
    def ready(self):
        super().ready()
        self.index_view = IndexView

    def get_urls(self):
        urls = super().get_urls()
        urls += [
            url(r'^$', self.index_view.as_view(), name='index'),
        ]
        return self.post_process_urls(urls)

这在myproject/myapp/offer/apps.py中。 myapp是在django-oscar教程之后创建的,该教程涉及运行命令./manage.py oscar_fork_app order myapp

文件夹的一般分类:

myproject:
    - myproject
        - settings.py
        ...
    - static
    - myapp
        - order
        - offer
            - apps.py
        - __init.py
    - templates
    manage.py

myproject中的我的urls.py看起来如下:

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import url
from django.conf.urls.static import static
from django.conf import settings
from django.apps import apps

urlpatterns = [
    path('i18n/', include('django.conf.urls.i18n')),
    url(r'^', include(apps.get_app_config('oscar').urls[0])),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

此刻我要添加的视图非常非常基本:

from django.views.generic import TemplateView


class IndexView(TemplateView):
    template_name = "pages/index.html"

    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        products = ['empy', 'for', 'now']
        context.update({
            'products': products,
        })
        return context

我在做什么错?

我正在使用django-oscar 2.0.4django 2.2.12python 3.7.4

django python-3.x django-views django-urls django-oscar
1个回答
0
投票

索引位于:oscar / apps / catalogue / apps.py

您必须分叉目录

© www.soinside.com 2019 - 2024. All rights reserved.