{"id":34979703,"url":"https://github.com/persteenolsen/django-starter-two","last_synced_at":"2026-05-25T14:31:55.450Z","repository":{"id":290174957,"uuid":"973590387","full_name":"persteenolsen/django-starter-two","owner":"persteenolsen","description":"Python and Django Website hosted at Vercel using MySQL. Ready for serving static files and using Django models for a Blog, Employees and Todos. DevOps by GitHub and Vercel Cloud","archived":false,"fork":false,"pushed_at":"2026-01-02T08:00:30.000Z","size":1259,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-08T05:38:50.320Z","etag":null,"topics":["django","mysql","python","vercel"],"latest_commit_sha":null,"homepage":"https://django-starter-two.vercel.app","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/persteenolsen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-27T10:15:03.000Z","updated_at":"2026-01-02T08:00:34.000Z","dependencies_parsed_at":"2025-04-27T11:39:40.720Z","dependency_job_id":"c7071f6b-d6bc-4eea-8fdb-6e9a1aac8a45","html_url":"https://github.com/persteenolsen/django-starter-two","commit_stats":null,"previous_names":["persteenolsen/django-starter-two"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/persteenolsen/django-starter-two","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Fdjango-starter-two","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Fdjango-starter-two/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Fdjango-starter-two/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Fdjango-starter-two/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/persteenolsen","download_url":"https://codeload.github.com/persteenolsen/django-starter-two/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/persteenolsen%2Fdjango-starter-two/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33479912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T14:31:05.219Z","status":"ssl_error","status_checked_at":"2026-05-25T14:31:02.878Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","mysql","python","vercel"],"created_at":"2025-12-27T00:55:26.663Z","updated_at":"2026-05-25T14:31:55.437Z","avatar_url":"https://github.com/persteenolsen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# Python + Django + MySQL + Models + CRUD + Vercel\n\nThis example shows how to use Django 5.1.11 on Vercel with Serverless Functions using the [Python Runtime](https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python).\n\nLast updated: 18-05-2026\n\nNode version selected at Vercel Cloud: 22\n\n## Demo at Vercel\n\nhttps://django-starter-two.vercel.app/\n\n## Installing\n\n- Download Python from the official website [Python](https://python.org/)\n- Make sure that you have installed Python by the command in Powershell: \"python --version\"\n- Download the Python extension for Visual Studio Code which automatically include the Pylance extionsion\n- Download / fork this Django Starter Website from my GitHub\n- Create the virtual envirement \".venv\" for the Django Web App by Powershell or by VS Code\n- Virtual Enviroment by VS Code: \"View - Command Palette - Python Create Enviroment\"\n\n## Install by Python commands in Powershell at Windows 10\n\n- python -m venv .venv\n\n- cd .venv\n\n- Scripts/activate\n\n- Copy requirements.txt to .venv\n\n- (.venv) pip install -r requirements.txt\n\n- (.venv) pip freeze \u003e requirements.txt\n\n- (.venv) cd ../\n\n- (.venv) python manage.py runserver\n\nWhen starting the Django Website from the Vertual Enviroment (.venv) you will notice that Django 5.1.11 will start. Otherwise you can use the Global Django if you have one installed by running:\n\n- python manage.py runserver\n\nThe Administration Backend can use MySQL for Dev + Prod but can also work with a SQLite DB for developement locally ( Dev )\n\n## How it Works\n\nOur Django application, `example` is configured as an installed application in `vercel_app/settings.py`:\n\n```bash\n# vercel_app/settings.py\nINSTALLED_APPS = [\n    # ...\n    'example',\n]\n```\n\nWe allow \"\\*.vercel.app\" subdomains in `ALLOWED_HOSTS`, in addition to 127.0.0.1:\n\n```bash\n# vercel_app/settings.py\nALLOWED_HOSTS = ['127.0.0.1', '.vercel.app']\n```\n\nThe `wsgi` module must use a public variable named `app` to expose the WSGI application:\n\n```bash\n# vercel_app/wsgi.py\napp = get_wsgi_application()\n```\n\nThe corresponding `WSGI_APPLICATION` setting is configured to use the `app` variable from the `vercel_app.wsgi` module:\n\n```bash\n# vercel_app/settings.py\nWSGI_APPLICATION = 'vercel_app.wsgi.app'\n```\n\nThis Django example uses the Web Server Gateway Interface (WSGI) with Django to enable handling requests on Vercel with Serverless Functions.\n\n## Routing \n\nThere are severals views in `example/views.py` which load HTML Django Templates `templates`:\n\nThe views are exposed a URL through `example/urls.py`:\n\n```bash\n# example/urls.py\nfrom django.urls import path\n\nfrom example.views import index\nfrom example.views import about\nfrom example.views import me\n\nurlpatterns = [\n    path('', index),\n    path('about', about),\n    path('me', me),\n]\n```\nFinally, it's made accessible to the Django server inside `vercel_app/urls.py`:\n\n```bash\n# vercel_app/urls.py\nfrom django.urls import path, include\n\nurlpatterns = [\n    ...\n    path('', include('example.urls')),\n]\n```\n\n## Templates\n\nTo use templates create the dir 'templates' at root level and put the HTML files there\n\nThere is only one Django App in the Project and the dir 'templates' can be at root level\n\nTell Django where to look for Templates by `example/settings.py`:\n\nFind the section TEMPLATES = [] and add the dir of the Templates\n\n'DIRS': [BASE_DIR / 'templates']\n\n## Running Locally\n\n```bash\npython manage.py runserver\n```\nYour Django application is now available at `http://127.0.0.1:8000/`.\n\n## The Admin Backend and Databases\n\nThe Admin Backend is using a MySQL Database for both Dev + Prod, but is able to use a SQLite for Dev\n\nTo connect to the MySQL install the Python package \"pymysql\" and the packages from the requirements.txt\n\n```bash\npip install -r requirements.txt\n```\n\nTake a look at the files needed for connecting to MySQL: `vercel_app/mysql_setup.py` and \n\n`vercel_app/__init__.py`\n\nCreate a Super User for the Admin Backend in the MySQL\n\n```bash\npython manage.py createsuperuser\n```\n\nMake the Migration to the MySQL DB\n\n```bash\npython manage.py makemigrations\npython manage.py migrate\n```\nYou will need to do the Migration at first and when / if you will add, update or delete models.py which this Django Web App does not use\n\nFor using a SQLite developing / locally make the config in the setting file `vercel_app/settings.py`\n\nFind the section DATABASES = {} and add support for SQLite and comment out the MySQL\n\n## Static files for the Admin Backend and the Frontend\n\nThere is only one Django App in the Project and the dir 'static' and 'assets' can be created at root level\n\nMake sure that the Python package 'whitenoise' is installed from the requirements.txt\n\nNote: Make sure you have the line 'whitenoise.middleware.WhiteNoiseMiddleware' in the \n\nMIDDLEWARE = [] at the `vercel_app/settings.py` along with the other packages\n\nFinally, take a look at `vercel_app/settings.py`:\n\nFind where Django now looks for the static files\n\nSTATIC_URL = 'static/'\n\nWhere you put your static files in the dir 'static'\n\nSTATIC_ROOT = BASE_DIR/'static' \n\n## Additional directory from which to load static files if wanted\n\nThe files in the dir 'asset' will be copied to the dir 'static' after running\n\n```bash\npython manage.py collectstatic\n```\n\nThe static files for the Admin Backend will also be created in the dir 'static' by the above command\n\nSTATICFILES_DIRS = [\n\n    os.path.join(BASE_DIR, 'assets')\n]\n\n## Check that Django is serving static files by URL\n\nType the URL in your Browser after deployment to Vercel\n\nhttps:// your project at vercel.app/static/pso-django.jpg\n\nor the URL when running locally\n\n`http://127.0.0.1:8000/static/pso-django.jpg`\n\nIf everything is fine my photo will be displayed\n\nThe CSS files can be tested the same way like the .jpg above\n\nNow you can use the images and CSS in your Templates\n\n## Running Locally and take a look at the Admin Backend\n\n```bash\npython manage.py runserver\n```\n\nThe Django application is now available at `http://127.0.0.1:8000/admin`\n\n## Deployment to Vercel\n\nMake sure that your static files are ready by running\n\n```bash\npython manage.py collectstatic\n```\n\nTake a look at the file `vercel.json`\n\nMake sure to set Debug = False in the file `vercel_app/settings.py`\n\nMake a commit to your GitHub and your Django will build and deploy\n\n## Things for improvement\n\nYou could try to add a model.py for the Admin Backend + Frontend\n\n## Models\n\nAdd three simple Models \"Post\", \"Employee\" and \"Todo\" to be administrated by the Admin Backend and displayed by the Frontend. The \"Employee\" and \"Todo\" can also be adminstrated by the Frontend by CRUD\n\n- Create a file `example/models.py` with your new Model Post Employee and Todo\n\n- Make a regitration of your Models in `example/admin.py`\n\n- Create the View for handling the Posts Employees and Todos `example/views.py`\n\n- Add the view / template blog employees and todos in `example/urls.py`\n\n- Create a Template for display the Posts `templates/blog.html`\n\n- Create a Template for display the Employees `templates/employees.html`\n\n- Create a Template for display the Todos `templates/todos.html`\n\n- Create a folder with the path: `example/migrations` and run the command:\n\n```bash\npython manage.py makemigrations example\n```\nNote: It is important to add the name of the app in the command `example` !!!\n\nThis command will create a file for the migration of the Models to three Tables in the MySQL DB\n\n- Now run the command: \n\n```bash\npython manage.py migrate\n```\nThis will create the Tables Post Employee and Todo in the DB and you are now ready for administrate the Posts Employees and Todo by the Django Admin Backend\n\n## Customize Templates of the Admin Backend\n\nI customized the Header of the Django Admin to make sure it always will have a minimum height to avoid\nthat the responsive menu sometimes is hidden. That can happen when there is a lot content in some of the Admin pages like change password or when Recent History grows. Create a folder admin inside the templates and copy the below files from your Django installation. Then in the templates / admin I customized:\n\n- base.html\n\n- base_site.html\n\n- base_theme_toogle.html \n\n- index.html\n\n- login.html\n\nIn the vercel_app / urls.py the Django Admin Title and Header text was customized\n\n## Tips and tricks\n\nHide the Django Secret Key which keeps your app secure by signing cookies, passwords, and other sensitive data \n\nOpen Powershell and generate a new secret key:\n\n- python manage.py shell \n\nNow paste the following lines of code\n\n```bash\n\u003e\u003e\u003e from django.core.management.utils import get_random_secret_key\n\u003e\u003e\u003e print(get_random_secret_key())\n```\nA Secrey key will be printed which you can copy and save in the .env file and by environment variables in Production\n\nNote: You may want to have a url safe secret key if your host not allows specials charactars in the enviroment variables and you can use:\n\n```bash\n\u003e\u003e\u003e import secrets\n\u003e\u003e\u003e print(secrets.token_urlsafe(50))\n```\nThis will also print a Secret key\n\nLeave the shell by typing:\n\n```bash\n\u003e\u003e\u003e exit()\n```\nHappy use of Django :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Fdjango-starter-two","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpersteenolsen%2Fdjango-starter-two","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersteenolsen%2Fdjango-starter-two/lists"}