我想在dashboard
应用中添加一些网址/观看次数。所以我使用oscar_fork_app
分叉了应用程序。我在fork app.py
app文件夹中创建了一个dashboard
文件。还在app.py
应用内添加了catalogue
内dashboard
个子应用。关注this。
我的#dashboard/app.py
from oscar.apps.dashboard.app import DashboardApplication as CoreDashboardApplication
class DashboardApplication(CoreDashboardApplication):
name = 'dashboard'
permissions_map = {
'index': (['is_staff'], ['partner.dashboard_access']),
}
index_view = get_class('dashboard.views', 'IndexView')
catalogue_app = get_class('dashboard.catalogue.app', 'application')
def get_urls(self):
urls = [
url(r'^catalogue/', include(self.catalogue_app.urls)),
]
return self.post_process_urls(urls)
application = DashboardApplication()
我的#dashboard/catalogue/app.py
from oscar.apps.dashboard.catalogue.app import CatalogueApplication as CoreCatalogueApplication
class CatalogueApplication(CoreCatalogueApplication):
name = None
csv_upload_view = get_class('dashboard.catalogue.views',
'CSVUpload')
def get_urls(self):
urls = [
url(r'^csvupload/$',
self.csv_upload_view.as_view(),
name='csvupload'),
]
return self.post_process_urls(urls)
application = CatalogueApplication()
当我点击/dashboard
时,它说
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/dashboard/
Using the URLconf defined in teashop.urls, Django tried these URL patterns, in this order:
^i18n/
^admin/
^accounts/reviews/$ [name='review-list']
^accounts/subscriptions/$ [name='subscriptions']
^accounts/storecredit/$ [name='storecredit']
^catalogue/
^basket/
^checkout/
^accounts/
^search/
^dashboard/ ^catalogue/
^offers/
The current URL, dashboard/, didn't match any of these.
我是否必须将oscar.apps.dashboard.app中的所有网址粘贴到我的forked_app?什么是以正确方式扩展的方式?
答案 0 :(得分:1)
我必须添加父类的所有网址。
class DashboardApplication(CoreDashboardApplication):
...
catalogue_app = get_class('dashboard.catalogue.app', 'application')
def get_urls(self):
urls = super(DashboardApplication, self).get_urls()
urls += [
url(r'^catalogue/', include(self.catalogue_app.urls)),
]
return self.post_process_urls(urls)
同样适用于其他app.py
class CatalogueApplication(CoreCatalogueApplication):
name = None
csv_upload_view = get_class('dashboard.catalogue.views',
'CSVUpload')
def get_urls(self):
urls = super(CatalogueApplication, self).get_urls()
urls += [
url(r'^csvupload/$',
self.csv_upload_view.as_view(),
name='csvupload'),
]
return self.post_process_urls(urls)
application = CatalogueApplication()