Search Posts

Category: python

AngularJS ng-view not showing up using $routeProvider templates

Directory Structure: public film – film.html – film-controller.js main – main.html – film-controller.js – app.js – index.html In my index.html file I have: <div ng-view> </div> in the body and ng-app=”myApp” in the starting html tag app.js angular.module(‘myApp’, [‘ngRoute’]).config(config); function config($routeProvider) { $routeProvider.when(‘/’, { templateUrl: ‘main/main.html’, controller: ‘MainController’, controllerAs: ‘vm’ }).when(‘/film/:id’, { templateUrl : ‘film/film.html’, controller: ‘FilmController’, controllerAs: ‘vm’ }).otherwise({ redirectTo : ‘/’ }); } In main.html I have a <h1>Hello {{}}</h1> line of code […]

Increment integer field dynamically – Django

So I have the following model: from django.db import models class Person(models.Model): name = models.CharField(max_length=254) image_url = models.CharField(max_length=254) title = models.CharField(max_length=254) bio = models.CharField(max_length=20000) vote = models.IntegerField(default=0) def __str__(self): return Where Vote is the attribute that I want to increment by one on every click. The following Views: import json from rest_framework.views import APIView from rest_framework.response import Response from urllib.request import urlopen from .models import Person from .serializers import PersonSerializer from django.views.generic import ListView […]

Django restful api can not get file content

I use Django restful api + angularjs . Now ,I append to use angularjs upload file to server by Django restful api On the web front-end ,The Html is: <input type=”file” data-upload-file id=”uploadInputFile”> The angularjs’s code is : omapp.directive(“uploadFile”,function(httpPostFactory){ return { restrict:”A”, scope:true, link:function(scope,element,attr){ element.bind(‘change’,function(){ var formData = new FormData(); formData.append(‘file’, element[0].files[0]); console.log(formData.get(‘file’)) httpPostFactory(‘/api/uploadfile/’,formData.get(‘file’),function (callback) { console.log(callback); }) }) } }; }); omapp.factory(‘httpPostFactory’, function ($http,$cookies) { return function (file, data, callback) { var req = […]