大约2星期以来,我一直在尝试使我的应用在访问url时显示正确的HTML时遇到了麻烦,但这只是行不通。我正在关注本教程https://thinkster.io/django-angularjs-tutorial
我真的不确定是什么问题,我的所有JS文件都已加载
thinkster-routes.js:
(function () {
'use strict';
angular
.module('thinkster.routes', [])
.config(config);
config.$inject = ['$routeProvider'];
/**
* @name config
* @desc Define valid application routes
*/
function config($routeProvider) {
$routeProvider.when('/register', {
controller: 'RegisterController',
controllerAs: 'vm',
templateUrl: '/static/templates/authentication/register.html'
}).otherwise('/');
}
})();
register.html(应显示的内容)
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1>Register</h1>
<div class="well">
<form role="form" ng-submit="vm.register()">
<div class="form-group">
<label for="register__email">Email</label>
<input type="email" class="form-control" id="register__email" ng-model="vm.email" placeholder="ex. john@notgoogle.com" />
</div>
<div class="form-group">
<label for="register__username">Username</label>
<input type="text" class="form-control" id="register__username" ng-model="vm.username" placeholder="ex. john" />
</div>
<div class="form-group">
<label for="register__password">Password</label>
<input type="password" class="form-control" id="register__password" ng-model="vm.password" placeholder="ex. thisisnotgoogleplus" />
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
index.html:
<!DOCTYPE html>
<html >
<head>
<title>TixBlast</title>
<base href="/" />
{% include 'stylesheets.html' %}
</head>
<body>
{% include 'navbar.html' %}
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 ng-view"></div>
</div>
</div>
{% include 'javascripts.html' %}
</body>
</html>
views.py
from django.shortcuts import render
from rest_framework import permissions, viewsets
from authentication.models import Account
from authentication.permissions import IsAccountOwner
from authentication.serializers import AccountSerializer
from rest_framework.response import Response
import json
from django.contrib.auth import authenticate, login
from rest_framework import status, views
class AccountViewSet(viewsets.ModelViewSet):
lookup_field = 'username'
queryset = Account.objects.all()
serializer_class = AccountSerializer
def get_permissions(self):
if self.request.method in permissions.SAFE_METHODS:
return (permissions.AllowAny(),)
if self.request.method == 'POST':
return (permissions.AllowAny(),)
return (permissions.IsAuthenticated(), IsAccountOwner(),)
def create(self, request):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
Account.objects.create_user(**serializer.validated_data)
return Response(serializer.validated_data, status=status.HTTP_201_CREATED)
return Response({
'status': 'Bad request',
'message': 'Account could not be created with received data.'
}, status=status.HTTP_400_BAD_REQUEST)
urls.py
from django.conf.urls import patterns, url, include
from thinkster_django_angular_boilerplate.views import IndexView
from django.contrib import admin
from rest_framework_nested import routers
from authentication.views import AccountViewSet
admin.autodiscover()
router = routers.SimpleRouter()
router.register(r'accounts', AccountViewSet)
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
# ... URLs
url(r'^api/v1/', include(router.urls)),
url('^.*$', IndexView.as_view(), name='index'),
)