Flask
&
Django
dominik.wronski@gmail.com
O czym nie bedzie dzisiejsze wystapienie:
rekrutacja
Django:
"The Web framework for perfectionists with deadlines"
- spójne, calosciowe rozwiazanie
- swietna dokumentacja
- aktywna spolecznosc
"Flask is a microframework for Python
based on Werkzeug, Jinja 2
and good intentions."
from flask import Flask app = Flask(__name__)
@app.route('/') def index(): return "Hello, World!"
if name = "__main__":
app.run()
<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">
{{ user.username }}
</a></li>
{% endfor %}
</ul>
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
from sqlalchemy import Column, Integer, String
class Person(Base):
__tablename__ = 'persons'
id = Column(Integer, primary_key=True)
first_name = Column(String(30))
last_name = Column(String(30))
from sqlalchemy.sql import extract
entries_a_month = Entry.query.filter(
(extract(Entry.pub_date, 'year') == 2011) &
(extract(Entry.pub_date, 'month') == 1)
).all()
ActiveRecord
vs
Unity of Work
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^articles/(\d{4})/$', 'news.views.year_archive'),
url(r'^articles/(\d{4})/(\d{2})/$',
'news.views.month_archive'),
url(r'^articles/(\d{4})/(\d{2})/(\d+)/$',
'news.views.article_detail'),
)
www.our_domain.com/articles/2003/03/03/
Urls
from flask import request
@app.route('/todo/api/v1.0/tasks', methods = ['POST'])
def create_task():
if not request.json or not 'title' in request.json:
abort(400)
task = {
'id': tasks[-1]['id'] + 1,
'title': request.json['title'],
'description': request.json.get('description', ""),
'done': False
}
tasks.append(task)
return jsonify( { 'task': task } ), 201
Podsumowujac
Django:
- swietny jesli chcesz co mieć szybko
- niektóre elementy skladni sa $%#
- dojrzaly framework
- wszystko w pakiecie
Flask:
- swietny do pisania backendu
- przyjemniejsza skladnia
- "zeby dobrze wybrac trzeba
warto rozumiec co robimy"
Flask & Django - web development
By Dominik Wronski
Flask & Django - web development
Presentation made for infoMEET 8 Feb 2014 Wroclaw
- 2,579