Code Monkey home page Code Monkey logo

Comments (7)

rehandalal avatar rehandalal commented on June 4, 2024

Hey @ewino. Could you provide a traceback or some kind of indication of what the problem is that you are facing? The test suite is currently passing so I'm tempted to say the decorator works as expected.

If you happen to be working off of master instead of the PyPI release, I just fixed a small issue.

from flask-mobility.

ewino avatar ewino commented on June 4, 2024

Hi @rehandalal, there was no traceback, simply the original handler function was called by flask for both cases (with both request.MOBILE being True and False).

(Also, I've been working from the PyPI release, so that's probably not it)

from flask-mobility.

rehandalal avatar rehandalal commented on June 4, 2024

So I'm not sure I fully understand where your code is supposed to go or exactly what it's doing? Is there any chance you could post a snippet of your view function?

Also sometimes when you have multiple decorators on the view, things don't work as expected till you order them correctly. If you happen to have multiple decorators on the view, can you try reordering those decorators and seeing if that helps?

I've just updated the test suite to include all use cases and it works as expected.

from flask-mobility.

rehandalal avatar rehandalal commented on June 4, 2024

@ewino is this still an issue? or did the above suggestion help?

from flask-mobility.

ewino avatar ewino commented on June 4, 2024

Hi, sorry for my disapperance.

The bug surfaces in a code a simple as this one:

from flask import Flask, Response, jsonify, request
from flask.ext.mobility import Mobility
from flask.ext.mobility.decorators import mobilized
from flask.templating import render_template

app = Flask(__name__)
Mobility(app)

@app.route('/')
def home():
    return render_template('index.html')


@mobilized(home)
def home():
    return render_template('mobile.html')

if __name__ == '__main__':
    app.run('0.0.0.0', port=8888, debug=True)

(index.html is rendered both in mobile and not)

I have Flask v0.10.1 and Flask-Mobility==0.1.1 (installed from pip)

from flask-mobility.

rehandalal avatar rehandalal commented on June 4, 2024

Ah! I should update the docs to give a better example of how to use this. But basically here's what the above code should look like:

from flask import Flask, Response, jsonify, request
from flask.ext.mobility import Mobility
from flask.ext.mobility.decorators import mobilized
from flask.templating import render_template

app = Flask(__name__)
Mobility(app)


def home():
    return render_template('mobile.html')


@app.route('/')
@mobilized(home)
def home():
    return render_template('index.html')


if __name__ == '__main__':
    app.run('0.0.0.0', port=8888, debug=True)

from flask-mobility.

ewino avatar ewino commented on June 4, 2024

That seems as it would work (except, i think you mixed up the templates - was that intentional?), though it find it a bit less intuitive.
I figured the @mobilized decorator was receiving a legitimate handler (with a route) and declares another function as it's replacement for mobile devices (with no need to touch the original handler's part of the code). It seemed like a very elegant syntax.

Could you please consider adding the three lines of code from my first post to the decorator so both use-cases would work?

Thanks for your rapid replies!

from flask-mobility.

Related Issues (12)

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.