HolyBranches avatar

Documenting Working Codes - A Django Setup Routine that actually Works

holybranches

Published: 29 Apr 2021 › Updated: 29 Apr 2021Documenting Working Codes - A Django Setup Routine that actually Works

Documenting Working Codes - A Django Setup Routine that actually Works

My very first take on programming went like this:

Spent the whole day stuck on starting up a freaking django app
I ran this same shit yesterday and everything went well in the end.

And it went like that for a reason.

Whatever, we correcting that shit.

Systems over goals.

Tried to create multiple django projects multiple times today and got a hang of it.

Creating a Django Project, App and running it Till the apps.views return the desired output (Without PipEnv)

  1. Create a django project using 'django-admin startproject projectName'

  2. Run the manage.py server using 'python manage.py runserver'. If you are not sure whether you in the right directory, type 'dir' into the command line and hit enter. If manage.py shows up as one of the files in that directory, you good to go.

  3. Create an app inside the project by using 'python manage.py startapp appName'

*Now, one of the most frustrating thing I have ever faced since starting django is how I went from easily creating a project that at least take me all the way to the admin page to the one that continuously show me this:

Screenshot (281).png

After battling with it, I discovered the singular reason why that happens:

Not migrating means you will never SEE the ADMIN page!

  1. Migrate using 'python manage.py migrate'

Screenshot (282).png

  1. To be able to login through the admin page, create super user. With 'python manage.py createsuperuser'

  2. add newly created app to INSTALLED APPS in settings.py

  3. Create urls.py for the app

  4. Copy the main project's urls.py and copy it to the newly created app's urls.py then tweak it by by adding especially 'from . import views' ie import app.views into the app

  5. Go to the newly created app's views.py and create exactly what you want the user to see

END

Stack Used: python 3.7; django 3.2

Leave Documenting Working Codes - A Django Setup Routine that actually Works to:

Written by

The cool cat on any block.

Read more #python posts


Best Posts From HolyBranches

We have not curated any of holybranches's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From HolyBranches