def download(request, path): file_path = os.path.join(settings.MEDIA_ROOT, path) if os.path.exists(file_path): with open(file_path, 'rb') as fh: response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel") response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path) logger.info("successfully downloaded") return response logger.error("please verify again") raise Http404
def root(): sql = f"SELECT * FROM product_categories ORDER BY id ASC" # logger.warning('A warning occurred (%d apples)', 42) logger.error('An error occurred') logger.info(sql) response = mysqldb.fetch_rows(sql) if response['status']: print(response['rows']) return render_template('index.html')
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() logger.info("successfully uploaded") # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form logger.info("form is loaded successfully") # Load documents for the list page documents = Document.objects.all() data = serializers.serialize('json', documents) logger.info(data) # Render list page with the documents and the form return render_to_response( 'list.html', {'documents': documents, 'form': form}, context_instance=RequestContext(request) )
#!/usr/local/bin/python from myapp import app, logger logger.info('starting flask') app.run(host='0.0.0.0',port=5000)
def test(request): content = {} logger.info("success") return render_to_response('test.html',context_instance=RequestContext(request))