Documenting Working Codes - A Django Setup Routine that actually Works

in #python4 years ago

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

Sort:  

Yay! 🤗
Your post has been boosted with Ecency Points, by @penderis.
Use Ecency daily to boost your growth on platform!

Support Ecency
Vote for Proposal
Delegate HP and earn more