ספריית קטעי קוד

קטעי קוד בדוקים ומוכנים להעתקה ב-Python, Flask, JavaScript, SQL, HTML, CSS ו-Bash. אפשר לפתוח כל אחד מהם במגרש המשחקים.

8 קטעי קוד

flask

Application factory

Create the app in a function so tests and production can each build their own.

beginner #structure#config#blueprints
flask

Safe file upload

Check the extension, size and filename before saving an upload.

intermediate #uploads#security#files
flask

JSON error handlers

Return JSON instead of HTML for API errors.

beginner #api#errors#json
flask

Login-required decorator for JSON routes

Answer 401 JSON instead of redirecting to the login page.

intermediate #auth#decorators#api
flask

Paginate a query

Paginate with Flask-SQLAlchemy and keep page numbers safe.

beginner #sqlalchemy#pagination#database
flask

Rate limit a route

Stop brute-force attempts with Flask-Limiter.

beginner #security#rate-limit#login
flask

Send CSRF token with fetch

Put the token in a meta tag and send it as X-CSRFToken from JavaScript.

beginner #csrf#security#javascript
flask

Signed, expiring links

Make email-verification or reset links that expire, without a database table.

intermediate #auth#email#tokens