Search Posts

Category: python

How to send image as input to django view using angular frontend?

I have an existing django web api with angular frontend, using which i can upload images and display them to the user.Now i want to extend this.On clicking the button “segment”(see image) it should pass the corresponding image to my python script on the backend, which does some processing on the image. I have my python script in the views.py file of the main app,which is some thing like this: from django.shortcuts import render def […]

How to re-sort search results in-place without having to re-send a request in django?

Here is the scenario: I have a search page, with some form elements providing multiple filter conditions (something like ‘advanced search’), and probably a nested ListView to display the search results in-place. What I would like to achieve: Whenever the user changes some filter conditions, the result list below responds in-place (taking another request for this could be accepted); When the user changes the sorting option, the results change their ordering immediately, without sending another […]

Passing Streaming Data from Python Flask REST (Backend) to Angular JS (FrontEND) : Excel Export

I am trying to add a download button to my webpage to download an excel file using Python flask as backend and AngularJS 1.5 as frontend. I am trying to get the data from the database, prepare a workbook and convert it to byte stream. Below is the code written in Flask: @data.route(‘/export_data’,methods=[‘POST’]) @cross_origin() def export_data(): # Flask response bio = io.BytesIO() data = [[‘Alex’,10],[‘Bob’,12],[‘Clarke’,13]] df = pd.DataFrame(data,columns=[‘Name’,’Age’],dtype=float) # By setting the ‘engine’ in the […]

Creating a Webapp for mobile phones with python and firebase [on hold]

Two friends and I have an idea for an app that we would like to create ourselves. We have basic programming abilities regarding python, vba, html, javascript, css and sql. We wanted to create the app with firebase as our main foundation. The app we want to create should be a webapp that runs on browsers and on smartphones. To be honest, we do not know what the best approach is. We don’t have the […]

Escape additional characters with Django autoescape

I’m trying to extend Django default autoescape behavior to escape the {} characters. The issue is our Django templates are printing inline JS templates (angular.js). But this means some variable django prints might contains {{}} characters that are going to be executed – thus allowing XSS. We’re usually doing escapes and backend validation, but some old pages might’ve skipped the basic checks. Any chance we can hook directly in the autoescape behavior to also HTMl […]

Selenium selector doesn’t work

I’m trying to scrape the following page made with AngularJs (i think) but it doesn’t work when i try to select and then click on the link named “Learn more” (at the end of the following code). I don’t know what the problem is, could you help me ? <article class=”tactic”> <div class=”tactic__info”> <header class=”tactic__header”> <div class=”tactic__category label-text label-text–small”> <!—-> <!—-> Traffic </div> <h5 class=”formatted-text tactic__name” ng-bind-html=”$ctrl.name”>Video Retargeting Audience</h5> <div class=”tactic__tags”> <tags-display tags=”$ctrl.tags” on-tag-click=”$ctrl.searchByTag”><!—-><span ng-repeat=”tag […]

Django REST framework custom format for all out responses

In my project I use DRF as backend and Angular as frontend. Django==1.10 djangorestframework==3.7.1 I need all responses from DRF to be in the following format. { “status”: “”, // 200,400,…..etc “error”: “”, // True, False “data”: [], // data “message”: “” // Success messages } for this i have written a custom viewset and overridden the functions list, detail, create, update class ResponseModelViewSet(viewsets.ModelViewSet): def list(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) page = self.paginate_queryset(queryset) […]

How can I access the variable in my js file which rendered from flask? [duplicate]

This question already has an answer here: Is it possible to use Angular with the Jinja2 template engine? 2 answers Pass parameter with Python Flask in external Javascript 2 answers In python flask displaying a variable in a .html file by render_template(“index.html”, message=”hello world”) and in index.html file we can access the it {{message}} expression. As my R&D This expression is same for the angular.js for binding $scope variable. But in my .js file I […]

How can I incorporate an angular JS in flask python framework?

Please bare with me as I have a background in mechanical engineering. I’m hosting a small website using flask. I recently came across a nice project called “gamepad HTML5”, it basically shows me all the info about the gamepad connected to my computer. I took the code from github and could make it work in my codepen: https://codepen.io/diamondx911/pen/mBgYgJ But when I try to put it in my html folder it doesn’t work (note that I […]

Next Page »