我正在建立一个简单的网站,我想为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中的其他页面。关于需要做什么的任何想法?
答案 0 :(得分:1)
您可以通过Django设置应用程序在Angular和您的基本URL上的路由,轻松设置Mezzanine在HTML5 Mode中使用Angular,确保任何未被捕获的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...
)
On 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。