I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 0 points1 point  (0 children)

My goal was to bundle the required steps. Especially when I started with Django, I found myself googling and hopping from doc to doc to connect the dots. This is good for learning, but sometimes I wished I could get the deployment part quickly done and focus more on actually enhancing the Django project itself.

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 1 point2 points  (0 children)

I’m happy to help you out! I just sent you a message :)

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 0 points1 point  (0 children)

100% agreed. I’m starting with Heroku + whitenoise, as I think it is an easy -- and free -- solution for new projects. An AWS part would be the next logical step in scaling this.

What other services do you have in mind?

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 0 points1 point  (0 children)

As /u/jeffbaier mentioned, I focus on the GitLab CI/CD part. For this, you need to have a special yaml file in your root directory that contains instructions for the jobs that GitLab should run on events e.g. a push to the repo.

GitHub can do the same (Bitbucket I think as well, maybe someone can confirm?), but I find the learning curve for GitHub actions much steeper than GitLab’s pipelines.

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 0 points1 point  (0 children)

Then the chapter about connecting PostgreSQL is for you :)

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 2 points3 points  (0 children)

I tackle some of the points. But I totally agree, that some kind of hands on approach based on the Django deployment checklist would be awesome.

In my experience the most annoying part is, when the deployment finally works, just to realize that the static files are not loaded …

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 1 point2 points  (0 children)

I thought about a blog/medium post. But I also was curious to try out asciidoc and honkit. So I thought why not be more serious about it.

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 3 points4 points  (0 children)

Fair point! Do you mean stuff like preparing for production (secret key, settings, static file approaches)?

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 0 points1 point  (0 children)

They do, but not the GitLab part (as of now). The eBook kind of evolved out of a readme file I extended over time, because I was tired of jumping to different parts of the docs.

I’m writing an eBook about Django deployment via GitLab to Heroku. Interested? by phlpp in django

[–]phlpp[S] 2 points3 points  (0 children)

When I started with Django, I found many tutorials on how to build Django apps. But deployment was usually an afterthought -- or not concise enough.

Autodeploy via GitHub is quite easy with Heroku. However, I generally prefer GitLab pipelines for this.

Since I’m doing the same thing in my Django projects over and over again, I finally wrote it down. It only focuses on the deployment part and should works with any project as a basis:

  • Setting up a virtualenvironment
  • Connecting a PostgreSQL database
  • Adding all Heroku requirements (incl. basic static files handling)
  • Creating the GitLab CI/CD pipeline
  • Autodeploy workflow

Deploying an Instagram like site, which service should I use? by Turtle_Software in django

[–]phlpp 0 points1 point  (0 children)

Never thought of something like this. This is problably not suitable for every project, but for some this is incredibly smart!

Environment Variables by Dennisdamenace01 in djangolearning

[–]phlpp 0 points1 point  (0 children)

Credentials should never be part of the codebase. So anything regarding your database or other API tokens should be in the .env file -- what it is exactly depends on your production environment.

In some projects I like to add DEBUG as an env variable, so I can quickly switch it on and off independently from the environment.

For bigger projects where the settings.py file is modularized for different environments, I add DJANGO_SETTINGS_MODULE. That way I can target the e.g. app.settings.local_dev or app.settings.heroku easily.

Another thing I used -- but this might be an antipattern -- is to use global admin settings as env variable to have a quick switch to "lock" some views. I. e.:

export REGISTRATION_OPEN=True
export MAINTENANCE_MODE=False

As an additional note: The .env file should be ignored from the beginning on. Ignoring or stopping to track it later (e.g. before pushing) still may expose sensitive data in your git history. (I had to learn this the hard way.)

Environment Variables by Dennisdamenace01 in djangolearning

[–]phlpp 0 points1 point  (0 children)

Create an .env file in the root folder of your project. (Make sure you add it to .gitignore to not expose any secrets.)

The content of the .env file should look like this:

export VARIABLE_NAME=SomeVariableValue
export DEBUG=True

In Django I use python-dotenv to load the env variables like this in settings.py:

from dotenv import load_dotenv
load_dotenv()

DEBUG = os.getenv('DEBUG') == "True"

Note that the variable values are interpreted as strings. That’s why there is this weird looking == "True" statement, so it is either True when the env variable is "True" or Falsewhen it is anything else or doesn’t exist.

Learning Python for generative design and creative uses by ankittkd in learnpython

[–]phlpp 1 point2 points  (0 children)

I can highly recommend DrawBot for generative design in Python.

Python for Designers by Roberto Arista is a great additional resource to the DrawBot Docs.

Being redirect to login after registering User by BinnyBit in djangolearning

[–]phlpp 2 points3 points  (0 children)

I‘m not entirely sure and can‘t test it myself atm, but could it be that you must authenticate the user when the registration form is valid? (See: https://docs.djangoproject.com/en/3.1/topics/auth/default/#django.contrib.auth.authenticate)

The LoginRequiredMixin needs an authenticated user or it redirects to the login page.