8/10/2023 0 Comments Megasync tutorialMixins are an OOP pattern that promotes spaghetti code if not done carefully, especially in Python where there is no encapsulation. You add some decorators to require an authenticated user and/or some permissions. You have a function, which takes a request and URL parameters, and returns an HTTP response. Like I said, you don't need class-based views if you split your code correctly. Also, IMHO the urls.py from Django is vastly superior to the route decorator from Flask. No SMTP setup required.Īll of those tips might seem obvious, but they get you far, very far. I usually make a mailjet account, add my API key to my settings, and use the mailjet backend of django-anymail. This is, by far, the best library out there. Then you only need one Docker image, one gunicorn, and if you deploy in Kubernetes, one Ingress resource. Instead, use Whitenoise to force Django to serve staticfiles but with the correct HTTP cache headers so services like Cloudflare can take over after the first request (usually done by your E2E test suite by the way). Which is a bit more complicated to deploy. You can work with HTMX, Django Forms, small views that call your business code and return some small rendered template, then sprinkle some Alpine.JS (or jQuery) on top of it, and you get your SSR SPA that scales well enough.īy default, Django won't serve staticfiles in production, you need to distribute them via a CDN. Then, why would you need a REST/GraphQL API? Server Side Rendering is coming back into trends, huge SPA that are heavy on the client's resource are becoming less frequent. Django provides many function decorators that are easier to reason about (login_required, permission_required, require_http_methods. Most of the time, you don't need class-based views.Ī small function which call your business code and render a JSON document, or an HTML document is more than enough. This allows you to make your views quite small because all the logic is not there.ģ. Then I have the Django apps in `myproject.apps.` which imports from `myproject.lib`. In most project, I have the package `myproject.lib` which contains all the business code, easily testable and mockable. Separate your business code from your Django apps See my gist as an example for the `settings/_init_.py`. Settings/envs/test.py : Test suite settings Settings/envs/prod.py : Production settings (read from env vars, the 12 factors app way) Settings/envs/dev.py : Development settings Settings/base.py : The basic settings of your project (your apps, middlewares. Settings/core.py : The stuff that Django generates and that you touch almost never Settings/_init_.py : Import the correct settings This is inspired by Elixir's compile-time config per environment/release/etc. I have some tips I use in all my Django projects:ġ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |