Demonstration server for python project. Created to explore using Heroku for hosting python (Django) projects.
Django is configured to use python's included SQLite database system. This default behavior is wonderful for locally hosting, but it's unsuitable for production. I intended to host this on Heroku, which has a free version of a PostgreSQL database that is recommended for production.
Djangocentral has a great article on using 'PostgreSQL with Django'. I'm including my own instructions here for convenience, customization, and learning-by-documenting:
I'm using Windows and I prefer winget to click-through-installers. Use the later if you dare, but I use:
winget install -e --id PostgreSQL.PostgreSQL
(This seems to install an unfortunately outdated version of the GUI application, but the database itself is okay.)
Log in to PostgreSQL with the default postgres
user. When prompted, enter the default password (postgres
):
psql -U postgres
CREATE DATABASE takushi;
CREATE USER takushi_u WITH ENCRYPTED PASSWORD 'takushi_u_Password';
ALTER ROLE takushi_u SET client_encoding TO 'utf8';
ALTER ROLE takushi_u SET default_transaction_isolation TO 'read committed';
ALTER ROLE takushi_u SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE takushi TO takushi_u;
psql can be exited with \q
If you want to log in to PostgreSQL with this user, use the command:
psql -U takushi_u -d takushi
Enter the password when prompted.
py manage.py migrate
You should now be able to run your server with either:
py manage.py runserver
heroku local -f Procfile.windows
(heroku local
if your Unix)
dblog was written to be served on github pages and I'd like to keep that system in place for backwards compatibility/precedence.
To integrate it to this site though, it seems as though the best option is to generate the static pages on my machine and add these derived files to version control. Since Jekyll is a Ruby Gem and not a python file, this seems like it can't be offloaded to a remove server. Life is truly suffering.
winget install -e --id RubyInstallerTeam.Ruby
Broken. Following official documentation https://jekyllrb.com/docs/installation/windows/.
Use the GUI installer athttps://rubyinstaller.org/.
gem install jekyll bundler
Confirm successful installation with jekyll -v
Note that you may have to install several other gems. I had to install:
wdm
webrick
jekyll-mentions
github-pages
This probably works better on Linux.
bundle exec jekyll build --layouts djangoTemplates -d dblogDjango
--layouts djangoTemplates
will use django-specific/generated templates. This is done to allow gitHub pages hosting to continue to use the native content in_layouts
. In the future these should be reconciled.-d dblogDjango
will set the destination in a new folder. This is to protect the native_site
for gitHub pages. As above, this could be reconciled/simplified in the future.
Per https://docs.djangoproject.com/en/4.0/topics/auth/default/#creating-users, create a superuser by using:
[heroku run]
python manage.py createsuperuser --username=joe [email protected]
TODO: This could be done in an automatic script, but since it doesn't work in an AppConfig
's ready()
function (database loading problem(?)), doing it by hand will suffice for now.
Install coverage.py with
pip install coverage
coverage run --source='.' manage.py test
coverage report
coverage html