<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Erik Laco on Medium]]></title>
        <description><![CDATA[Stories by Erik Laco on Medium]]></description>
        <link>https://medium.com/@erik_48905?source=rss-3beedbee496c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZRUKSywXsmJPFQopkG4qRg.png</url>
            <title>Stories by Erik Laco on Medium</title>
            <link>https://medium.com/@erik_48905?source=rss-3beedbee496c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:15:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erik_48905/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[10 Common Django Deployment Mistakes (And How to Avoid Them)]]></title>
            <link>https://medium.com/@erik_48905/10-common-django-deployment-mistakes-and-how-to-avoid-them-7ca2faac8f62?source=rss-3beedbee496c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ca2faac8f62</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Erik Laco]]></dc:creator>
            <pubDate>Fri, 04 Apr 2025 17:53:48 GMT</pubDate>
            <atom:updated>2025-04-04T17:53:48.821Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*ijp-7bROfC3Z3ZY5vdHrhg.png" /></figure><p>Deploying a Django project to production isn’t just about running <strong>python manage.py runserver</strong>. A lot can go wrong — and often does — especially if you’re new to Django or DevOps practices.</p><p>Here’s a breakdown of 10 common pitfalls developers run into when deploying Django projects, and how to steer clear of them.</p><p>🚀 <a href="https://seenode.com/">I built <strong>seenode</strong> — a platform where you can easily deploy all your Django apps.</a></p><p>Give it a try and let me know what you think — I’d love your feedback! 🙌</p><p>Here is the full <a href="https://seenode.com/blog/10-common-mistakes-when-deploying-django-projects-and-how-to-avoid-them/"><strong>original blog post</strong></a><strong>.</strong></p><h3><strong>1. ❌ Keeping the Default SECRET_KEY</strong></h3><p><strong>The risk:</strong> Using Django’s default SECRET_KEY or committing it to version control is a security red flag.</p><p><strong>The fix:</strong> Generate a strong, random key for production and keep it out of your codebase.</p><pre>import secrets<br>print(secrets.token_urlsafe(50))</pre><p>Use environment variables or tools like <a href="https://github.com/joke2k/django-environ">django-environ</a> to keep secrets… secret.</p><h3><strong>2. ❌ Leaving DEBUG = True in Production</strong></h3><p><strong>The risk:</strong> This exposes detailed error pages to users. That’s a free buffet for attackers.</p><p><strong>The fix:</strong> Always set:</p><pre>DEBUG = False<br>ALLOWED_HOSTS = [&#39;yourdomain.com&#39;]</pre><h3><strong>3. ❌ Serving Static and Media Files with Django</strong></h3><p><strong>The risk:</strong> Django’s dev server isn’t meant to handle static/media in production. It’s slow and inefficient.</p><p><strong>The fix:</strong> Use a web server like <strong>Nginx</strong> or a CDN to serve static assets. For cloud projects, consider django-storages with S3 or GCS.</p><pre>location /static/ {<br>    root /path/to/static;<br>}<br>location /media/ {<br>    root /path/to/media;<br>}</pre><h3><strong>4. ❌ Using SQLite or Misconfigured Databases</strong></h3><p><strong>The risk:</strong> SQLite isn’t production-ready. Misconfigured databases can kill performance.</p><p><strong>The fix:</strong> Switch to <strong>PostgreSQL</strong> or <strong>MySQL</strong> and fine-tune your settings.</p><pre>DATABASES = {<br>    &#39;default&#39;: {<br>        &#39;ENGINE&#39;: &#39;django.db.backends.postgresql&#39;,<br>        &#39;NAME&#39;: &#39;mydb&#39;,<br>        &#39;USER&#39;: &#39;myuser&#39;,<br>        &#39;PASSWORD&#39;: &#39;mypassword&#39;,<br>        &#39;HOST&#39;: &#39;localhost&#39;,<br>        &#39;PORT&#39;: &#39;5432&#39;,<br>    }<br>}</pre><h3><strong>5. ❌ Hardcoding Secrets and Config</strong></h3><p><strong>The risk:</strong> Putting API keys, DB credentials, etc., directly in settings.py makes your app vulnerable.</p><p><strong>The fix:</strong> Store them in environment variables:</p><pre>import os<br>SECRET_KEY = os.getenv(&#39;DJANGO_SECRET_KEY&#39;)</pre><p>Use <strong>.env</strong> files with django-environ or python-decouple for smoother config management.</p><h3><strong>6. ❌ No Caching Strategy</strong></h3><p><strong>The risk:</strong> Without caching, your app hits the DB constantly = slow performance.</p><p><strong>The fix:</strong> Use Redis or Memcached.</p><pre>CACHES = {<br>    &#39;default&#39;: {<br>        &#39;BACKEND&#39;: &#39;django.core.cache.backends.redis.RedisCache&#39;,<br>        &#39;LOCATION&#39;: &#39;redis://127.0.0.1:6379/1&#39;,<br>    }<br>}</pre><p>Also check out @cache_page and Django’s low-level caching API.</p><h3><strong>7. ❌ Missing Security Headers</strong></h3><p><strong>The risk:</strong> No headers = exposed to XSS, clickjacking, and other threats.</p><p><strong>The fix:</strong> Enable SecurityMiddleware and tweak these settings:</p><pre>SECURE_BROWSER_XSS_FILTER = True<br>SECURE_CONTENT_TYPE_NOSNIFF = True<br>X_FRAME_OPTIONS = &#39;DENY&#39;</pre><p>Consider using django-csp for a strong Content Security Policy.</p><h3><strong>8. ❌ No Logging or Monitoring</strong></h3><p><strong>The risk:</strong> No logs = no clue what went wrong in production.</p><p><strong>The fix:</strong> Use Django’s logging config with tools like Sentry, Grafana, or Prometheus.</p><pre>LOGGING = {<br>    &#39;version&#39;: 1,<br>    &#39;handlers&#39;: {<br>        &#39;file&#39;: {<br>            &#39;level&#39;: &#39;ERROR&#39;,<br>            &#39;class&#39;: &#39;logging.FileHandler&#39;,<br>            &#39;filename&#39;: &#39;/var/log/django_errors.log&#39;,<br>        },<br>    },<br>    &#39;root&#39;: {<br>        &#39;handlers&#39;: [&#39;file&#39;],<br>        &#39;level&#39;: &#39;ERROR&#39;,<br>    },<br>}</pre><h3><strong>9. ❌ Deploying Manually</strong></h3><p><strong>The risk:</strong> Manual deployments are error-prone and inconsistent.</p><p><strong>The fix:</strong> Automate with CI/CD pipelines (GitHub Actions, GitLab CI, Jenkins, etc.)</p><p>Example GitHub Action:</p><pre>name: Deploy Django<br>on: [push]<br>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v2<br>      - name: Deploy<br>        run: ./deploy.sh</pre><h3><strong>10. ❌ Using runserver in Production</strong></h3><p><strong>The risk:</strong> Django’s built-in server isn’t made for production. It doesn’t scale.</p><p><strong>The fix:</strong> Use Gunicorn or uWSGI behind a reverse proxy like Nginx or Traefik.</p><pre>gunicorn myproject.wsgi:application --bind 0.0.0.0:8000</pre><h3><strong>Final Thoughts</strong></h3><p>Shipping Django projects to production isn’t just about having working code — it’s about making sure it stays working, securely and efficiently.</p><p><strong>Ready to deploy your Django app?</strong></p><p>🚀 <a href="https://seenode.com/">Try seenode — built by devs, for devs.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ca2faac8f62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Escape Python Dependency Hell with Just 2 Commands]]></title>
            <link>https://medium.com/@erik_48905/escape-python-dependency-hell-with-just-2-commands-3245fb0c0bb8?source=rss-3beedbee496c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3245fb0c0bb8</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Erik Laco]]></dc:creator>
            <pubDate>Tue, 19 Nov 2024 11:24:36 GMT</pubDate>
            <atom:updated>2024-11-19T11:24:36.972Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*03Wg31E_T4iqm0JhmqhEDg.png" /></figure><h3>Introduction</h3><p>If you’ve ever worked on a Python project, chances are you’ve encountered <em>dependency hell</em> — that frustrating situation where package versions clash, breaking your code and wasting hours of debugging. But don’t worry! With the right tools, you can escape this chaos.</p><p>In this post, I’ll show you how to use <strong>pip-tools</strong> — specifically <strong>pip-compile</strong> and <strong>pip-sync</strong> — to take control of your Python packages.</p><h4>pip freeze &gt; requirements.txt:</h4><p>Saves all installed packages and their versions from your current environment but includes everything, even indirect dependencies.</p><h4>pip-compile:</h4><p>Starts with your direct dependencies, resolves versions for all required packages, and creates a clean, conflict-free requirements.txt</p><h3><strong>Advantages of Using pip-tools</strong></h3><ul><li>Automatically resolves and locks package versions</li><li>Keeps all environments in sync with <strong>pip-sync</strong></li><li>Makes upgrades safer and easier to manage</li><li>Prevents version conflicts and unexpected bugs</li></ul><p><strong>Instead of this:</strong></p><pre>annotated-types==0.7.0<br>anyio==4.6.2.post1<br>build==1.2.2.post1<br>click==8.1.7<br>fastapi==0.115.5<br>idna==3.10<br>packaging==24.2<br>pip-tools==7.4.1<br>pydantic==2.9.2<br>pydantic_core==2.23.4<br>pyproject_hooks==1.2.0<br>setuptools==75.5.0<br>sniffio==1.3.1<br>SQLAlchemy==2.0.36<br>starlette==0.41.3<br>typing_extensions==4.12.2<br>wheel==0.45.0</pre><p><strong>Keep the list of packages like this:</strong></p><pre>FastAPI<br>SQLAlchemy</pre><h3>Let’s get dive into it</h3><p>I kept using <strong>pip install</strong> for every package and then <strong>pip freeze &gt; requirements.txt</strong> to save them, but it always led to a chaotic, unreliable file — sound familiar?</p><h4>Setup</h4><p>For the reference, let’s say I have a simple <strong>FastAPI</strong> app working with <strong>PostgreSQL</strong> database. So I need to install FastAPI and SQLAlchemy.</p><blockquote>You’d probably wanted to create a virtual environment first to keep all the packages separated for a specific project but I’m not going to cover it in this post.</blockquote><h4>1. Create requirements.in file</h4><p>Run this command to create an empty <strong>requirements.in</strong> file</p><pre>$ cat requirements.in</pre><p>Then open it in your favourite text editor (mine is vim) and add these 2 lines:</p><pre>FastAPI<br>SQLAlchemy</pre><p>I don’t need any specific version of FastAPI nor the SQLAlchemy package so I keep it simple.</p><h4>2. Install pip-tools</h4><p>Run this command to install pip-tools</p><pre>$ pip install pip-tools</pre><h4>3. Create requirements.txt file</h4><p>Now when you have installed pip-tools you can run <strong>pip-compile</strong> command which generates the the list of all the packages and it’s versions you need to install.</p><pre>$ pip-compile requirements.in</pre><p>When you run this command, it saves the output of the command into <strong>requirements.txt</strong> file whihc might look like this:</p><pre>#<br># This file is autogenerated by pip-compile with Python 3.12<br># by the following command:<br>#<br>#    pip-compile requirements.in<br>#<br>annotated-types==0.7.0<br>    # via pydantic<br>anyio==4.6.2.post1<br>    # via starlette<br>fastapi==0.115.5<br>    # via -r requirements.in<br>idna==3.10<br>    # via anyio<br>pydantic==2.9.2<br>    # via fastapi<br>pydantic-core==2.23.4<br>    # via pydantic<br>sniffio==1.3.1<br>    # via anyio<br>sqlalchemy==2.0.36<br>    # via -r requirements.in<br>starlette==0.41.3<br>    # via fastapi<br>typing-extensions==4.12.2<br>    # via<br>    #   fastapi<br>    #   pydantic<br>    #   pydantic-core<br>    #   sqlalchemy</pre><p>This requirements.txt, created with pip-compile, keeps your dependencies tidy, reliable, and easy to understand — no more messy surprises!</p><h4>4. Install packages with pip-sync</h4><p>The very last command of the whole setup is <strong>pip-sync </strong>which syncs the packages in your environment with the ones provided in the requirements.txt file.</p><pre>$ pip-sync requirements.txt</pre><p>Use pip-sync for managing dependencies in non-clean environments, but skip it in clean setups like new Docker builds in CI/CD pipelines, where pip install -r requirements.txt is enough.</p><p>To double check the correct versions you can run the command again and you should get the outbue like:</p><pre>$ Everything up-to-date</pre><p>You can also check it by running command pip-freeze and compare result with the requirements.txt file.</p><pre>$ pip freeze<br>annotated-types==0.7.0<br>anyio==4.6.2.post1<br>build==1.2.2.post1<br>click==8.1.7<br>fastapi==0.115.5<br>idna==3.10<br>packaging==24.2<br>pip-tools==7.4.1<br>pydantic==2.9.2<br>pydantic_core==2.23.4<br>pyproject_hooks==1.2.0<br>setuptools==75.5.0<br>sniffio==1.3.1<br>SQLAlchemy==2.0.36<br>starlette==0.41.3<br>typing_extensions==4.12.2<br>wheel==0.45.0</pre><h3>Final words</h3><p>Managing Python dependencies can feel overwhelming, but tools like pip-compile and pip-sync make it easier to maintain clean, reliable, and conflict-free environments.</p><p>Whether you’re working on a local setup or deploying in CI/CD pipelines, these tools are a must-have in your Python toolbox</p><p>🚀 <strong>Let’s keep learning and growing together — happy coding!</strong> 🚀</p><p>If you’ve found this guide helpful, I’d love to hear your thoughts! Feel free to connect with me for more tips and discussions:</p><ul><li><a href="https://x.com/Erik80503163">Follow me on X</a></li><li><a href="https://www.linkedin.com/in/erik-laco/">Connect with me on LinkedIn</a></li></ul><p>Happy coding 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3245fb0c0bb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>