Comments (7)
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.
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.
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.
@ewino is this still an issue? or did the above suggestion help?
from flask-mobility.
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.
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.
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)
- Create test suite HOT 1
- Use/depend on user-agents package for better analysis of user agent strings? HOT 6
- Not compatible with Flask 3.0.0 and later. HOT 2
- Error: While importing "app", an ImportError was raised: HOT 2
- Error generated. HOT 3
- Meet requirements for Flask approved extensions HOT 7
- flask.request.MOBILE might be regex match instead of bool HOT 1
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- Remove .travis.yml file HOT 3
- Use flask-small theme for docs HOT 1
- Website not updated with `from flask_mobility` import HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-mobility.