Putting these here because they're rather ugly and disorganized. Only fit for desperate searching. Will implement a better readme while this one is phased out.
These are notes that are meant to help maintain, understand, and re-launch the project in case things go wrong.
# To refresh the server after changing most files (HTML, CSS, JS)
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
sudo nginx -t && sudo systemctl restart nginx
# settings.py - Use these settings:
DEBUG = True
ALLOWED_HOSTS = []
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
# To run the (winenv) on Windows Environment for Django:
& winenv/Scripts/Activate.ps1
Yes, the "&" is necessary.
# While in (winenv), run:
python manage.py runserver --insecure
Interestingly enough, because your windows environment and linux environment are separate (for python/django), your super-user in your linux environment is NOT the same as your super-user in your windows environment. This also means you will need to create superusers separately in both your winenv and linux env:
# Create a super user for BOTH python environments (1 - Linux, 2 - Windows):
python manage.py createsuperuser --username=cocothegorilla
Tips:
When you try to run gunicorn after adding the gunicorn.service file, but something goes wrong, it's probably because the directories you listed are wrong. Check all ...3? places where you list your own directory in the 'gunicorn.service' file. It is a very likely source of your problems. Also, don't forget to check for random added or deleted characters in the service file.
Protip : When fixing the gunicorn.service file, don't forget to run:
sudo systemctl daemon-reload sudo systemctl restart gunicorn
And when you run:
sudo journalctl -u gunicorn
Don't forget to SCROLL to the bottom of the output, where all the latest output is. Otherwise, you are only READING OLD ERRORS. Don't waste time with that.
https://www.digitalocean.com/community/questions/how-to-set-domain-name-django-nginx-ubuntu-16-04
https://www.youtube.com/watch?v=MP3Wm9dtHSQ
Handling "www.(...)" Redirects:
https://www.youtube.com/watch?v=6QYJUvrb7m8
https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf
Even though they're [background images] and {% static %} is being super weird (and is throwing errors):
https://simpleit.rocks/python/django/call-static-templatetag-for-background-image-in-css/
Lesson learned: it's okay to throw errors.
This is the filepath for the mysql settings.
/etc/mysql/mysql.conf.d/mysqld.cnf
https://stackoverflow.com/questions/4093603/how-do-i-find-out-my-mysql-url-host-port-and-username
TCP Forwarding on host (remote) server for TCP/IP connection: https://serverfault.com/questions/616696/lost-connection-to-mysql-server-at-reading-initial-communication-packet-syste
Digital Ocean specific: https://www.digitalocean.com/community/questions/how-do-i-use-ssh-to-access-mysql-remotely
We need to take some steps to shut down mySQL so that we can edit the root password and access the default database.
# All-in One Package:
# includes Apache, phpMyAdmin, mySQL, etc...
https://www.apachefriends.org/index.html
https://www.inmotionhosting.com/support/edu/cpanel/kill-mysql-processes-phpmyadmin/
https://www.wikihow.com/Install-phpMyAdmin-on-Your-Windows-PC
https://www.apachelounge.com/download/ https://www.youtube.com/watch?v=oJnCEqeAsUk
PROTIP: Watch the installation directory and unzip process carefully. You unzip into your drive directory, not just anywhere!
install php (on windows 10, 2021) https://www.youtube.com/watch?v=QMWb_Wn2g5k
https://www.digitalocean.com/community/tutorials/how-to-secure-mysql-replication-using-ssh-on-a-vps
https://www.a2hosting.com/kb/developer-corner/mysql/connecting-to-mysql-using-python
https://stackoverflow.com/questions/37964325/how-to-find-and-disable-mysql-strict-mode
https://docs.djangoproject.com/en/4.0/intro/tutorial02/
https://stackoverflow.com/questions/24813536/django-admin-not-showing-models/24814041
"Double-check that you've actually registered your models in admin.py"
from MyApp.models import MyModel
admin.site.register(MyModel)
Protip: it may need to be in the APP folder, not your PROJECT folder. I.E.:
"project/blog/admin.py" rather than "project/admin.py"
https://stackoverflow.com/questions/9498012/how-to-display-images-from-model-in-django/9498359
https://steelkiwi.com/blog/best-practices-working-django-models-python/
nginx setup with media and static folders for django (serving media files on deployed live website with debug = false):
newsfeed.Artwork.file: (fields.E202) ImageField's 'upload_to' argument must be a relative path, not an absolute path.
HINT: Remove the leading slash.
# try
upload_to = 'artworks/'
# because settings.MEDIA_ROOT is absolute. We want relative!
Declaring variables:
Access Array Indices:
Error Handling Try/Except in Django:
https://stackoverflow.com/questions/8524077/catching-exceptions-in-django-templates
"'xyz' tag is not a registered tag library":
"How about we skip all that and just use ZIP two combine the two dictionaries?"
https://groups.google.com/g/django-users/c/rucw6bKFdz8?pli=1
https://www.geeksforgeeks.org/python-convert-two-lists-into-a-dictionary/
https://www.adamsmith.haus/python/answers/how-to-zip-two-lists-in-python
https://docs.djangoproject.com/en/dev/topics/forms/#customizing-the-form-template
https://docs.djangoproject.com/en/4.0/ref/settings/#std-setting-EMAIL_TIMEOUT
https://git-scm.com/docs/gitignore
https://www.youtube.com/watch?v=AkkBc_d7OXk
https://www.guru99.com/python-dictionary-append.html
https://stackoverflow.com/questions/18987051/how-do-i-unit-test-django-urls
https://stackoverflow.com/questions/54498123/django-secret-key-generation/54498318
python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"
Description: This 'second run' part is specifically made up of new solutions I've had to implement for the coldcut website. The 'first part' of this document contains a lot of documentation from florasora.com's readme.
From here on out, the documentation will tackle new subjects not tackled for florasora.com, such as User Authentication, specific REST frameworks, React, and various other even more advanced and specific topics.
https://pypi.org/project/django-bootstrap-v5/
How to get bootstrap to load in html files in django:
https://django-bootstrap-v5.readthedocs.io/en/latest/quickstart.html#example-template
https://stackoverflow.com/questions/21346045/django-new-fonts
https://stackoverflow.com/questions/10835500/how-to-change-text-transparency-in-html-css
https://www.portiva.nl/portiblog/blogs-cat/3-levels-of-css-selectors-to-select-all-elements
part 1 - https://www.youtube.com/watch?v=QFDyXWRYQjY part 2 - https://www.youtube.com/watch?v=fr3yF30GWi0 documentation for djoser - https://djoser.readthedocs.io/en/latest/getting_started.html
Tip: 'jwt' means JSON Web Token
These are added in after some other django/react JWT support libs are installed. Meaning that
this list is not exhaustiv--there is a part 1.
npm install --save axios react-router-dom redux redux-devtools-extension react-redux redux-thunk
Overall, these tools will help us implement redux in the application and debug what's going on.
facebook/create-react-app#4438
"make sure you run this route"
(Route proceeds to include specifically index.html and not whatever .html I think I want.)
https://reactrouter.com/docs/en/v6/getting-started/tutorial
React Router tutorial
npm audit
npm audit fix --force
https://redux-toolkit.js.org/api/configureStore https://redux.js.org/introduction/why-rtk-is-redux-today
https://www.geeksforgeeks.org/creating-python-virtual-environment-windows-linux/
# ----
# FOR WINDOWS:
# ----
# Install virtualenv
pip install virtualenv
# Create a virtualenv
virtualenv mywinenv
# Activate the virtualenv
mywinenv\Scripts\activate
# if that doesn't work, try:
& 'mywinenv\Scripts\Activate.ps1'
# to Deactivate the virtual env:
deactivate
# ----
# FOR LINUX:
# ----
# Install pip
sudo apt-get install python-pip
# Install virtualenv
pip install virtualenv
# Check version of virtualenv
virtualenv --version
# Create a virtual environment
virtualenv myenv
# for specific python versions:
virtaulenv -p /usr/bin/python2.7 myenv
# activating the env:
source myenv/bin/activate
# deactivating the env:
deactivate
https://www.pythoncentral.io/how-to-update-python/
On windows, you cannot update python with pip.
Download the windows python installer from the official website.
https://reactjs.org/tutorial/tutorial.html
https://www.youtube.com/watch?v=rxRYEXBmM88
# Jist of the terminal commands (for a django/react project geared for user authentication):
>virtualenv winenv
>winenv/Scripts/Activate
>pip install django
>django-admin startproject coldcmerch
>cd coldcmerch
>python manage.py startapp users
# need json webtoken authentication and REST framework compatibility:
>pip install djangorestframework djangorestframework-simplejwt
https://www.django-rest-framework.org/
tags: overriding, is_staff, is_admin, AUTH_USER_MODEL setting, custom user model
https://docs.djangoproject.com/en/4.0/topics/auth/customizing/
https://www.django-rest-framework.org/api-guide/status-codes/
Add this into package.json inside react/client/src:
"devDependencies": {
"react-scripts": "5.0.1"
},
# test the project for vulnerabilites as if it were in production (rather than dev)
npm audit --production
https://code.visualstudio.com/docs/editor/codebasics
# terminal window 0 - Run Django
cd coldcmerch
python manage.py runserver
# terminal window 1 - Run React
cd react
cd client
npm start
# terminal window 2 - Run Express
cd react
npm start
python manage.py flush
yes
Summary: template literals require grave accents, not straight quotation marks
i.e.: <`> and not <'>
When attempting to bridge React and Django via django's api views and urls, try changing localhost:8000 within the react directory to 127.0.0.1:8000. This is because Django runs on 127.0.0.1, not on localhost. Weird, right? Imagine spending 12 hours trying to fix that problem. Not me! Ahahahaha.
https://stackoverflow.com/questions/34563454/django-imagefield-upload-to-path
https://github.com/bmentges/django-cart/blob/master/cart/models.py
https://stackoverflow.com/questions/48670101/django-list-items-based-on-a-foreign-key
https://docs.djangoproject.com/en/3.2/intro/tutorial07/
This was so useful for displaying everything Coldcut will need on one page! SICK! They'll be able to add shirt sizes, colors, and images with just a few clicks! (if they ever need to)