aahnik / django-polling-site

My implementation after following the official tutorial from https://docs.djangoproject.com/en/3.1/intro/tutorial01/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

django-polling_site

django-polling_site ( Life's First Django Project)

GitHub license No Maintenance Intended | Archived

SEE SCREENSHOTS

HOW TO RUN ON YOUR COMPUTER

pre-requisites : python(3.8 or above) and pip must be installed

1. CREATE AND ACTIVATE A VIRTUAL ENVIRONMENT INSIDE A NEW DIRECTORY

Virtual Environments are a great way to wrap python projects. I have stopped working on this repo on Jul 15 2020. At the time of my work I have used the latest versions of python and django. If you are reading this after 2020, chances are new versions of python and django might have rolled out . So to ensure that old code runs smoothly , create a virtual environment.

Using Virtual Environments ensures the dependancies of each project is independently availaible and there is no headache of breakage of code and EVERY PROJECT STAYS INDEPENDENT OF ONE ANOTHER

IF YOU ARE NEW TO VIRTUAL ENVIRONMENTS READ PYTHON-3 OFFICIAL DOCS

2. CLONE THIS REPO django-polling-site IN YOUR DIRECTORY, AND INSTALL THE REQUIREMENTS

pip install -r requirements.txt

3. MOVE INSIDE THE pollsite DIRECTORY AND MAKE MIGRATIONS

python manage.py makemigrations poll
python manage.py makemigrations home
python manage.py migrate

4. CREATE A SUPERUSER , WITH YOUR OWN USERNAME AND PASSWORD

python manage.py createsuperuser

5. POPULATE DATABASE WITH DUMMY DATA OF QUESTIONS AND CHOICES, BY RUNNING THE populator_script FROM DJANGO SHELL click here to see how

6. Inside the home app directory , configure the homePage.yaml according to your wish Inside views.py of same directory, put the absolute path of homePage.yaml in the place instructed.

NOW RUN THE SERVER

python manage.py runserver

Go to http://127.0.0.1:8000/ . This is where Django starts server by default

HOLA !! ENJOY YOU HAVE SUCCESSFULLY RUN THE SERVER

Click on Admin button on top right corner to go the the Django Administration page. You can add team members , change or add questions and choices

Vist DJANGO'S OFFICIAL WEBSITE FOR MORE DETAILS..

you can now play around with the code your self

RUNNING SCRIPTs FROM DJANGO SHELL

inside apps you can't write your own scripts because they are run by django. Running a module directly will give lots of import errors

YOU WILL GET ERRORS IF YOU RUN THESE SCRIPT IN CWD CONTEXT

DON'T RUN DIRECTLY LIKE

python3 script.py

The exec() Function

exec() function is used for the dynamic execution of Python program which can either be in form of a string or object code. If it is a string, the string is parsed as a suite of Python statements which is then executed unless a syntax error occurs and if it is an object code, it is simply executed.

  1. START THE DJANGO SHELL BY RUNNING
$ python3 manage.py shell

(because Django Shell offers special access features)

  1. LOAD THE SCRIPT IN A VARIABLE
>>> script = open(script_path).read()
  1. EXECUTE THE SCRIPT IN PYTHON CONSOLE RUNNING IN DJANGO CONTEXT
>>> exec(script)

UPDATE : A BETTER WAY

python3 manage.py shell < myScript.py

About

My implementation after following the official tutorial from https://docs.djangoproject.com/en/3.1/intro/tutorial01/

License:MIT License


Languages

Language:Python 78.5%Language:HTML 21.5%