How do I host my html flask app for Beanstalk? - python

I have a website in html with it's scrip.js and script.css, I need to get it hosted in BeanStalk. I am trying to develop it into a python/flask app for the Python platform on beanstalk. If I am correct it is creating a app.py .ebextentions and requirments.txt?
I am just struggling to understand it all, how it all works. Using Pycharm to create the scripts and from what I could see I need a src file with the website files in there or another script?
Templates files were shown in the example, that being where the website housed I think but struggling as a whole to host this an application in a Python/Flask format for Beasntalk. It is only a single page at this moment.
from flask import Flask
app = Flask(__name__)
#app.route('/<index.html>')
def page(index.html):
return render_template('index.html')
if __name__ == '__template__':
app.run(__template__)
This is the code I have found have been playing around with it but still errors.
If anyone has any insight to this anything will help.
Thank you all.
This video is basically what I have been trying to replicate. And I am very new to Python so sorry for that haha.
<"https://www.youtube.com/watch?v=dhHOzye-Rms&list=PLwbyvxAyI6CvcFr6mV-Z-HAhM1jTItE8V&index=7">

Related

Static folder not reachable (Serving Angular apps on Flask)

I have an Angular app which I'm trying to serve from Flask server. The app runs on Flask but when I click a link on the app, the URL becomes ...../static/# instead of ...../# which results in PageNotFound error.
Basically, /static is being added to path. Do the files have to be placed in a specific way to avoid this issue? I have tried changing templateURL but don't quite know how this works.
This is what I've done: created template, static inside application. Copy-Pasted my Angular UI inside app. Created .py file to run the app. Built the angular app using ng build --base-href /static/. Then copied the .js files to static and index.html to templates folder.
The first page is alright but on clicking a link i go to ..../static/# which results in PageNotFound error.
IN A NUTSHELL, STATIC FOLDER CONTENT IS UNREACHABLE!
Also glyphicon isn't rendering properly when running on Flask but renders fine when running otherwise on localhost:4200. Instead it shows some other symbol on Flask. Some other styling also goes out of the window while using Flask but works otherwise.
Any suggestions are welcome.
Got it to work.
Just changed <a href="#"> to <a> and it started working!
Try building it using ng build --base-href or just ng build.
If this doesn't work then please show me your angular route and index.ts files.
In my projects, i never server static files from Angula/React/Vue from flask using CORS, i normaly create a separete HTTP server for frontend, it is egual how the server will be with Docker and Kubbernets,but if you prefer in this way, you can do something like this
from flask import send_from_directory,
#app.route('/<path:path>')
def send_static(path):
return send_from_directory(app.static_folder, path)

Jinja2 not work on flask/glitch.me deployment

I have a deployment of a tiny Flask app on Glitch. It seems to be working... sort of. However, the Jinja2 template engine is clearly not working, since all Jinja2 tags are being read into the browser as text. The application, which I have up on my GitHub page, works fine on the localhost. Can I fix this somehow?
Seems like this was not a problem with earlier versions of Flask and Python.
Firstly, adding the following debug option in the server.py file.
app.debug = True
Secondly, add some code as follows:
#app.after_request
def apply_kr_hello(response):
"""Adds some headers to all responses."""
...
response.headers['Cache-Control'] = 'no-cache'
return response
Thirdly, do a Ctrl-Shift-R on the specific browser tab where your application is being rendered.
That is it! Now, when you make changes to static file, they should be reflected in your app.
I presume one might also benefit from reading https://stackabuse.com/serving-static-files-with-flask as well.
I'm not a python expert but while your glitch project has the same code as localhost, your local machine is executing the code through a different path. In this case because there are no instructions for Glitch to start your project from mesostic.py it's just treating your project as a static website. (hence why the template tags are just being rendered out as text).
It might help to look at other python projects on glitch to get a sense of how to execute your .py file. e.g. checkout start.sh on https://glitch.com/edit/#!/python3-morepath. I'm not sure but you may also need a requirements.txt to tell Glitch that this is a python project.
Hope this gives you a place to start debugging from

Pass variable from a server web to python?

I´m running a html page on a server (using Xampp). Now, I would like take a variable from this html and pass it to python but i don´t the way. I don´t know if I can use Flask because I am running the html with Xampp.
Thank you!

Polymer Appengine Web page not rendering elements

I have begun developing a template for web development using the PWA and Polymer tutorial here: https://www.polymer-project.org/1.0/start/toolbox/set-up
I have gone through each step (1-4) and successfully deployed to appengine using python. When i serve the webpage on Localhost it renders all the polymerelements just fine, but once i deploy to appengine none of the elements get rendered.
Here are images of both.
Localhost:
Deployed to appengine:
Now I have double checked all the steps and i do not see anything i have missed. Any reason why this would not show up with any of the styling and elements? Once it is in appengine do I have to serve it like on localhost? All help is very appreciated, thanks in advance!
Let me know if you need any of the code as well. ALl of the code is exactly replicated from the tutorial link above.
EDIT: here are the errors im getting in my browser console:
Most of the errors are this one: this._desugarBehaviors is not a function

Jinja 2 markups showing when i try to use apache with a flask python coded webpage

The website is accessible by other computers by inputting the ip address of the host computer.
However, the jinja2 markups are shown.
Jinja2 markups image
And the links which use url_for do not work either.
Non-working url image
What is the issue here?
Please help! Thanks!
flask / jinja is not a "server page" type of technology like PHP, so jinja templates (which by themselves know nothing about flask - jinja can be used from any Python code) won't be automagically "interpreted". You have to configure your apache server to serve content from flask as documented here : http://flask.pocoo.org/docs/deploying/mod_wsgi/

Categories