gpt4 book ai didi

django - 与 angularjs 一起使用 mezzanine

转载 作者:行者123 更新时间:2023-12-01 19:49:29 25 4
gpt4 key购买 nike

我正在建立一个简单的网站,我想为 UI 集成 angularjs。然而,似乎 CMS 接管了一切并提供了一切,包括我想通过 angularjs 提供的任何东西。

我的 urls.py 文件:

urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
(r'^users/', include('apps.site_users.urls')),
url('^$', 'mezzanine.pages.views.page', {'slug': '/'}, name='home'),
url('', include('social.apps.django_app.urls', namespace='social')),
('^', include('mezzanine.urls')),
)

我对 angularjs 进行了所有必要的更改,因为没有 CMS,一切都加载得很好,但这意味着我无法提供 CMS 中的其他页面。关于需要做什么的任何想法?

最佳答案

您可以在HTML5 Mode中轻松设置Mezzanine以与Angular一起使用通过在 Angular 上设置应用程序的路由并通过 Django 设置基本 URL,确保任何未捕获的 URL 方案都重定向到“home”URL:

在 Django 上:

# urls.py
urlpatterns = patterns("",
# Change the admin prefix here to use an alternate URL for the
# admin interface, which would be marginally more secure.
("^admin/", include(admin.site.urls)),

# If you'd like more granular control over the patterns in
# ``mezzanine.urls``, go right ahead and take the parts you want
# from it, and use them directly below instead of using
# ``mezzanine.urls``.
("^", include("mezzanine.urls")),

# AngularJS HTML5 mode (ie, remove the /#/ from URLs):
# We need to redirect any uncaught URL schemes to the default home view.
# http://scotch.io/quick-tips/js/angular/pretty-urls-in-angularjs-removing-the-hashtag
url(r'^.*$', TemplateView.as_view(template_name='index.html'), name='home'),

# etc...
)

在 Angular 上:

// app.js
app.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: '/static/app/views/home.html',
})
.when('/profile/:profileId', {
templateUrl: '/static/app/views/profile.html',
controller: 'ProfileCtrl'
})
.when('/results', {
templateUrl: '/static/app/views/results.html',
controller: 'ResultsCtrl'
})
.otherwise({
redirectTo: '/'
});

$locationProvider.html5Mode(true);
});
});

在 HTML 上:

<!-- index.html -->
<!doctype html>
<html class="no-js" lang="es" ng-app="myApp">
<head>
<base href="/">
<!-- etc -->
</head>
<!-- etc -->
</html>

相关博客文章here .

关于django - 与 angularjs 一起使用 mezzanine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20383232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com