Git Product home page Git Product logo

flask-jsglue's Introduction

flask-jsglue's People

Contributors

absent1706 avatar fuhrysteve avatar henniss avatar hwdavidward avatar italomaia avatar jesseops avatar jonafato avatar stewartpark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-jsglue's Issues

ProxyPass Issue

When using ProxyPass on an apache sever to redirect to an internal server and using ReverseProxied, JSGlue doesn't acknowledge the use of a different URL. How do I fix this? for example

actual url is example.com/myapp/resource
JSGLUE url is example.com/resource

I need it to understand that its behind the /myapp

Problem with javascript and jinja tags?

I'm trying to do this within my imported javascript and it does read it upon page load

var x = {{x.title}}

So javascript must be embedded inside the jinja tempalte itself?

integrating Flask-JSGlue with Vue

If I'm building a web application using a Flask back-end but a Vue front-end instead of one based off the Jinja2 templating system, but still want to utilize Flask's url_for function in the front-end, what's the best way to do that?

Values are not URL encoded

Flask's url_for function encodes input to be URL safe. For example, url_for('root', someparam='5 & 6 & more') gives back /?someparam=5+%26+6+%26+more.

JSGlue doesn't escape the input at all. Flask.url_for("root", {"someparam": "5 & 6 & more"}) gives back /?someparam=5 & 6 & more.

Here's a fully working demo script:

import flask
from flask_jsglue import JSGlue

app = flask.Flask(__name__)
jsglue = JSGlue(app)
app.debug = True


home_template = u'''
<head>
    {{ JSGlue.include() }}
</head>
<body>
    Flask url: <code>{{ url_for('root', someparam='5 & 6 & more') }}</code>
    <br/>
    JSGlue url: <code id="jsglueurl"></code>

    <script>
        var jsglueUrl = Flask.url_for("root", {"someparam": "5 & 6 & more"});
        document.getElementById("jsglueurl").innerHTML = jsglueUrl;
    </script>
</body>
'''


@app.route("/")
def root():
    return flask.render_template_string(home_template)

if __name__ == "__main__":
    app.run()

You'll see the results on the page.

URLs generated by Flask.url_for() missing application root

My Flask application is deployed at a BASE_URL so that links to endpoints look like:
http://my_server/BASE_URL/endpoint/...
All URLs for Flask endpoints need to start with that BASE_URL. I find that links generated on the server side using {{ url_for(endpoint) }} work correctly, but links generated in Javascript on the client using Flask.url_for(endpoint) come out as
http://my_server/endpoint/...
with the application BASE_URL portion missing.

When viewed in a debugger both the flask server-side code and the jsglue client code seem to produce the same thing: "/endpoint/...", but the final URLs come out differently.

This may be user error, in which case I'd really appreciate some advice about how to solve it, or it may be a problem with URLs produced by jsglue.

Getting an absolute url

Thanks for all your work with js_glue, it has been very helpful.

I am currently trying to get an absolute url for one of my routes. I understand that this can be done by passing _external=True to the url_for function in Flask. Is this possible to do with js_glue?

I have tried the follow:
Flask.url_for('fn_name', { '_external': 'True' }) -- string of Python true.
Flask.url_for('fn_name', { '_external': true }) -- javascript true

Neither of them have managed to get the absolute url for the route.

Would you be able to advise if this is possible with js_glue, and if so, how do I get the absolute url?

Thanks in advance.

production does not see jsglue...

serving flask app on uwsgi and nginx for static files does not enable jsglue to work properly...
any reason why jsglue isn't being found?

is jsglue only good for development and not for production use?

Optional caching?

An optional integration with flask-cache could do some wonders here.

Command to persist jsglue js file

To make flask-jsglue SPA friendly, it would be nice to be able to generate the js file to disk with a command. Otherwise, it is quite difficult to import glue.js if the file is served from another domain.

jsglue.js is missing

I installed Flask-JSGlue2 through pip and I get the following error:

GET https://domain.com/jsglue.js net::ERR_ABORTED 500 (INTERNAL SERVER ERROR)

When I click it it takes me to the script tag which is the following:

<script src="/jsglue.js" type="text/javascript"></script>

I tried changing the JSGLUE_JS_PATH constant but it didn't help.

JsGlue should behave like Flask.url_for

When external is provided, JsGlue.url_for should use SERVER_NAME to build the path, not location, just like Flask.url_for. This behavior is quite useful for SPA websites.

Support to Quart

I have a project that is using Quart as backend instead of Flask. Although you can patch Flask in Quart for external libraries, there is an issue when make_response directive is used.
I adapted your flask_jsglue.py to use Quart instead but it would be nice to have that option in your library.

Thank you.

Issue with Jinja2 > 3.0.3

Hello,
With new version of Jinja2 the Python modules Markup and Escape should be imported from MarkupSafe (https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-1-1)

Actually it raise an exception :

File "/var/www/site_mbt/flask-app-v2/src/__init__.py", line 11, in <module>
    from flask_jsglue import JSGlue
  File "/var/www/site_mbt/flask-app-v2/venv/lib/python3.8/site-packages/flask_jsglue.py", line 2, in <module>
    from jinja2 import Markup
ImportError: cannot import name 'Markup' from 'jinja2' (/var/www/site_mbt/flask-app-v2/venv/lib/python3.8/site-packages/jinja2/__init__.py)

Thank you for your great job.

GET requests

I'm trying to do pagination with jsglue. how do i pass the parameters to a get request in my flask.url_for statement? inside the template?

Where is the jsglue.js?

I found the module need a javascript file called jsglue.js, but where should I get that file?

Needs an include and exclusion configuration

I was looking into using this but ended up writing a separate url helper to get around using back/front url_for for consistency because it was a simpler option.

Regardless, it seems like the lack of an inclusion/exclusion criteria config for url rules here is a potential (minor) security hazard, because it currently outputs the entire ruleset into jsglue.js. It's minor in the sense that we assume your URLs are already secure from unauthorized attacks, but not so minor in that you reveal information that should be obscure by design :-)

Have you considered e.g. reading a config parameter like a regex that specifies inc/exc rules? These would be either a single regex string, or a list/tuple of strings (for exact matches) or regex strings.

Briefly, if an inclusion rule is given, all rules are excluded by default, except for those matching the rule. If exclusion given, all are included by default except for those matching. If both given, all are excluded, except those matching inclusion, with exclusion rules would act as subfilters.

I don't know if I'll come back to this library but if I do, and this is still open, I will add this feature. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.