Rectangle 27 138

I would recommend that you start with Flask. With Flask, you will explicitly write your own route functions, make your routes render templates, etc. all using Python functions you're already familiar with. There is little "magic". You can see exactly how everything is happening and understand why it is happening. Flask documentation is also quite nice and concise so you can read it and learn Flask in a few hours, spend several evenings learning to make a full application, and then move on to Django. The time investment is small, it will give you great preparation for Django, and you'll have learned about a great micro-framework. I sometimes prototype projects in Flask before building them in Django.

Django, while more fully featured, has definite structure and convention so it can be a little more mysterious for a beginner to figure out how everything fits together. If you're new to web development, you might have some confusion about whether you're doing something because its a web development convention or whether you're doing it because its part of the Django conventions/organization.

If you can spend a few days or a week playing with Flask before moving on to learning Django (your original goal) I think it is well worth the time. Both are great frameworks. Welcome to the world of Web Development.

Hmmm, i've already started in django. Made some dynamic and static pages, I started to get good grasp of things in it. So do you have a link that explains what happens under the hood, instead of learning flask ? Because you're kind of a convincing talker :D

I don't have an under the hood summary of Django, unfortunately. One thing new developers are often confused about is how routing works. Here's the description for Django routing docs.djangoproject.com/en/dev/topics/http/urls and here's the description for Flask routing flask.pocoo.org/docs/quickstart/#routing It sounds like you've made a good start on Django already. Check the Django Tutorial if you haven't already - its pretty decent.

@dghubble Thank you VERY much for your well reasoned, well written answer. I know this question was closed as "not constructive", but I gotta tell you that your answer helped me figure out what Flask is, and how I might approach things moving to Python as my primary webdev language. You rock! :-)

@dghubble: If I am making APIs for mobile apps. Is flask a better choice ?

"Because it has more structure" is rarely a good reason to avoid something. Especially with a web framework, because it has a structure is the reason to use it. If you think Django's basic model-view-controller structure is "mysterious", then web development may not be your cup of tea...

python - Flask or Django for a beginner? - Stack Overflow

python django flask visual-web-developer
Rectangle 27 1

Might as well make this an answer. I had the same issue today and it was more of a non-issue than expected. After adding the CORS functionality, you must restart your Flask server (ctrl + c -> python manage.py runserver, or whichever method you use)) in order for the change to take effect, even if the code is correct. Otherwise the CORS will not work in the active instance.

from flask import Flask
from flask_cors import CORS  # This is the magic


def create_app(register_stuffs=True):
    """Configure the app and views"""
    app = Flask(__name__)
    CORS(app)  # This makes the CORS feature cover all routes in the app

    if register_stuffs:
        register_views(app)
    return app


def register_views(app):
    """Setup the base routes for various features."""
    from backend.apps.api.views import ApiView
    ApiView.register(app, route_base="/api/v1.0/")
from flask import jsonify
from flask_classy import FlaskView, route


class ApiView(FlaskView):
    @route("/", methods=["GET"])
    def index(self):
        return "API v1.0"

    @route("/stuff", methods=["GET", "POST"])
    def news(self):
        return jsonify({
            "stuff": "Here be stuff"
        })
Sending request:
GET /stuff
With parameters:
null
bundle.js:17316 Received data from Api:
{"stuff": "Here be stuff"}

javascript - Solve Cross Origin Resource Sharing with Flask - Stack Ov...

javascript python ajax flask cors
Rectangle 27 1

Might as well make this an answer. I had the same issue today and it was more of a non-issue than expected. After adding the CORS functionality, you must restart your Flask server (ctrl + c -> python manage.py runserver, or whichever method you use)) in order for the change to take effect, even if the code is correct. Otherwise the CORS will not work in the active instance.

from flask import Flask
from flask_cors import CORS  # This is the magic


def create_app(register_stuffs=True):
    """Configure the app and views"""
    app = Flask(__name__)
    CORS(app)  # This makes the CORS feature cover all routes in the app

    if register_stuffs:
        register_views(app)
    return app


def register_views(app):
    """Setup the base routes for various features."""
    from backend.apps.api.views import ApiView
    ApiView.register(app, route_base="/api/v1.0/")
from flask import jsonify
from flask_classy import FlaskView, route


class ApiView(FlaskView):
    @route("/", methods=["GET"])
    def index(self):
        return "API v1.0"

    @route("/stuff", methods=["GET", "POST"])
    def news(self):
        return jsonify({
            "stuff": "Here be stuff"
        })
Sending request:
GET /stuff
With parameters:
null
bundle.js:17316 Received data from Api:
{"stuff": "Here be stuff"}

javascript - Solve Cross Origin Resource Sharing with Flask - Stack Ov...

javascript python ajax flask cors
Rectangle 27 1

Might as well make this an answer. I had the same issue today and it was more of a non-issue than expected. After adding the CORS functionality, you must restart your Flask server (ctrl + c -> python manage.py runserver, or whichever method you use)) in order for the change to take effect, even if the code is correct. Otherwise the CORS will not work in the active instance.

from flask import Flask
from flask_cors import CORS  # This is the magic


def create_app(register_stuffs=True):
    """Configure the app and views"""
    app = Flask(__name__)
    CORS(app)  # This makes the CORS feature cover all routes in the app

    if register_stuffs:
        register_views(app)
    return app


def register_views(app):
    """Setup the base routes for various features."""
    from backend.apps.api.views import ApiView
    ApiView.register(app, route_base="/api/v1.0/")
from flask import jsonify
from flask_classy import FlaskView, route


class ApiView(FlaskView):
    @route("/", methods=["GET"])
    def index(self):
        return "API v1.0"

    @route("/stuff", methods=["GET", "POST"])
    def news(self):
        return jsonify({
            "stuff": "Here be stuff"
        })
Sending request:
GET /stuff
With parameters:
null
bundle.js:17316 Received data from Api:
{"stuff": "Here be stuff"}

javascript - Solve Cross Origin Resource Sharing with Flask - Stack Ov...

javascript python ajax flask cors
Rectangle 27 0

It's not smart to have python code inside java. Wrap your python code with flask or other web framework to make it as a microservice. Make your java program able to call this microservice (e.g. via REST).

Beleive me, this is much simple and will save you tons of issues. And the codes are loosely coupled so they are scalable.

Calling Python in Java? - Stack Overflow

java python jython
Rectangle 27 0

It's not smart to have python code inside java. Wrap your python code with flask or other web framework to make it as a microservice. Make your java program able to call this microservice (e.g. via REST).

Beleive me, this is much simple and will save you tons of issues. And the codes are loosely coupled so they are scalable.

Calling Python in Java? - Stack Overflow

java python jython