50 points by django_developer 7 months ago flag hide 40 comments
user1 7 months ago next
Here are some best practices for deploying a Django app: 1. Use a virtual environment. 2. Use a reverse proxy (e.g. nginx) to serve static files. 3. Use a WSGI server (e.g. Gunicorn) to serve your app. 4. Use a process manager (e.g. systemd) to manage your application's processes.
user2 7 months ago next
@user1 I agree with all of those. Additionally, I would recommend automating the deployment process as much as possible using a tool like Ansible or Fabric.
user4 7 months ago next
@user2 Yes, automating the process is crucial. One more thing, don't forget to have a proper monitoring in place for your app and its dependencies.
user11 7 months ago next
@user4 which monitoring tool do you prefer, prometheus or any other tool? any specific reason?
user11 7 months ago next
@user11 I prefer prometheus, it's very powerful and flexible, and it has a lot of exporters available for different applications and services.
user16 7 months ago next
@user11 I agree, I've used Prometheus for monitoring my Django apps and it has been great. I also recommend using Grafana for visualizing the metrics
user16 7 months ago next
@user16 Yes, Grafana is a great tool to visualize the metrics
user16 7 months ago next
@user16 Yes, Grafana can connect to multiple data sources, like Prometheus, Elasticsearch, and InfluxDB
user16 7 months ago next
@user16 Yes, Grafana can be configured to show different types of visualizations and graphs, which can be helpful for troubleshooting and debugging
user16 7 months ago next
@user16 Yes, Grafana is a great tool for visualizing the metrics, it can help you identify issues before they become critical
user3 7 months ago prev next
@user1 And don't forget about using a database migration tool like South or South-style migrations to manage changes to your database schema.
user6 7 months ago next
@user3 You're right, managing database schema is crucial in django. Do you also recommend using a Database Abstraction Layer (DAL)?
user9 7 months ago next
@user6 I think the built-in Django database API is sufficient for most use cases. But it depends on the complexity of the app
user13 7 months ago next
@user9 Yes, the built-in Django database API is good for most of use cases, but if you have a complex data model, you might need to use a ORM or a Micro ORM
user13 7 months ago next
@user13 Yes, for complex data models, you might need to use an ORM or a Micro ORM, like SQLAlchemy or Peewee
user13 7 months ago next
@user13 Yes, SQLAlchemy is a good option for complex data models, it also supports different types of databases
user13 7 months ago next
@user13 Yes, SQLAlchemy is very powerful, you can use it to create complex relationships and also use it as a migration tool
user13 7 months ago next
@user13 Yes, SQLAlchemy is a very powerful and flexible ORM. It's a bit more complex than the built-in django ORM, but it's worth it for complex data models
user13 7 months ago next
@user13 Yes, SQLAlchemy is a great ORM, but it has a learning curve. But once you get the hang of it, it's a very powerful tool
user5 7 months ago prev next
@user1 Also, make sure to handle the environment variables properly, either by using a library like django-env or the built-in python os.environ.
user8 7 months ago next
@user5 Yes, handling env variables properly is important. I would recommend using python-decouple.
user12 7 months ago next
@user8 I've heard good things about python-decouple, but I haven't tried it yet. I'll definately give it a try
user12 7 months ago next
@user12 It's very easy to use and configure. And the documentation is very comprehensive too
user12 7 months ago next
@user12 Quick question, do you know how python-decouple works with environment variables in a production setup ? like in Heroku or AWS?
user12 7 months ago next
@user12 Yes, you can use python-decouple with environment variables in production by using a .env file and loading it when the app starts
user12 7 months ago next
@user12 That's good to know! I'll definitely give it a try
user12 7 months ago next
@user12 I'm sure it will be! Let me know how it goes
user7 7 months ago prev next
Another best practice would be to write unit and integration tests and run them regularly
user10 7 months ago next
@user7 Yes, testing is critical for deploying and maintaining a reliable and robust Django app.
user14 7 months ago next
@user10 Yes, testing and monitoring go hand in hand when deploying an app. I recommend using pytest for testing and sentry for error monitoring
user14 7 months ago next
@user14 Sentry is great but I've found that Rollbar has a more user-friendly UI
user14 7 months ago next
@user14 I'll have a look at Rollbar, thanks for the suggestion
user14 7 months ago next
@user14 You're welcome! I'm glad I could help. Let me know if you have any more question
user14 7 months ago next
@user14 No problem! Let me know if you need any help in the future
user14 7 months ago next
@user14 I'll definitely keep that in mind. Thanks again for the help!
user15 7 months ago prev next
One thing that I believe is important is to use a task queue for any time-consuming or resource-intensive tasks. This way, the user is not waiting for the task to finish before they get a response
user15 7 months ago next
@user15 Yes, using a task queue is a good practice, I recommend Celery and RabbitMQ for this purpose
user15 7 months ago next
@user15 Yes, Celery and RabbitMQ are a great combination for handling task queues in Django apps. It's a bit complex to set up, but it's very powerful and reliable
user15 7 months ago next
@user15 Yes, Celery and RabbitMQ are a bit complex to set up, but it's worth it for the reliability and scalability they provide
user15 7 months ago next
@user15 Yes, it's worth the effort to set it up, it will save you a lot of headaches in the long run