├── .devcontainer ├── devcontainer.json └── icon.svg ├── .env.example ├── .gitattributes ├── .gitignore ├── README.md ├── hello_world ├── __init__.py ├── asgi.py ├── core │ └── views.py ├── settings.py ├── static │ ├── Octocat.png │ └── main.css ├── templates │ └── index.html ├── urls.py └── wsgi.py ├── manage.py └── requirements.txt /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "mcr.microsoft.com/devcontainers/universal:2", 3 | "hostRequirements": { 4 | "cpus": 4 5 | }, 6 | "waitFor": "onCreateCommand", 7 | "updateContentCommand": "pip install -r requirements.txt && python manage.py migrate", 8 | "postCreateCommand": "cp .env.example .env", 9 | "postAttachCommand": { 10 | "server": "python manage.py runserver" 11 | }, 12 | "customizations": { 13 | "codespaces": { 14 | "openFiles": [ 15 | "hello_world/templates/index.html" 16 | ] 17 | }, 18 | "vscode": { 19 | "extensions": [ 20 | "ms-python.python" 21 | ] 22 | } 23 | }, 24 | "portsAttributes": { 25 | "8000": { 26 | "label": "Application", 27 | "onAutoForward": "openPreview" 28 | } 29 | }, 30 | "forwardPorts": [8000] 31 | } 32 | -------------------------------------------------------------------------------- /.devcontainer/icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | SECRET_KEY=my_secret_key 2 | DEBUG=True 3 | 4 | # ALLOWED_HOSTS=yourdomain.com,anotherdomain.com (Each host is separated by a comma) 5 | ALLOWED_HOSTS=* 6 | 7 | DB_HOST=127.0.0.1 8 | DB_PORT=3306 9 | DB_DATABASE="" 10 | DB_USERNAME="" 11 | DB_PASSWORD="" 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-language=HTML+Django 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | db.sqlite3 2 | __pycache__/ 3 | staticfiles/ 4 | .env 5 | venv/ 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Codespaces ♥️ Django 2 | 3 | Welcome to your shiny new Codespace running Django! We've got everything fired up and running for you to explore Django. 4 | 5 | You've got a blank canvas to work on from a git perspective as well. There's a single initial commit with what you're seeing right now - where you go from here is up to you! 6 | 7 | Everything you do here is contained within this one codespace. There is no repository on GitHub yet. If and when you’re ready you can click "Publish Branch" and we’ll create your repository and push up your project. If you were just exploring then and have no further need for this code then you can simply delete your codespace and it's gone forever. 8 | 9 | ## installing dependancies 10 | 11 | ```python 12 | pip install -r requirements.txt 13 | ``` 14 | 15 | ## To collect static files: 16 | 17 | ```python 18 | python manage.py collectstatic 19 | ``` 20 | 21 | ## To run this application: 22 | 23 | ```python 24 | python manage.py runserver 25 | ``` 26 | -------------------------------------------------------------------------------- /hello_world/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/codespaces-django/3816b9147ddde21dc0e547c9496d1e29b6ee68df/hello_world/__init__.py -------------------------------------------------------------------------------- /hello_world/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for hello_world project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello_world.settings") 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /hello_world/core/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | def index(request): 4 | context = { 5 | "title": "Django example", 6 | } 7 | return render(request, "index.html", context) 8 | -------------------------------------------------------------------------------- /hello_world/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for hello_world project. 3 | 4 | Generated by 'django-admin startproject' using Django 5.0.4. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/5.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/5.0/topics/settings/ 11 | """ 12 | 13 | import os 14 | from pathlib import Path 15 | from decouple import config 16 | 17 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 18 | BASE_DIR = Path(__file__).resolve().parent.parent 19 | 20 | 21 | # Quick-start development settings - unsuitable for production 22 | # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ 23 | 24 | # SECURITY WARNING: keep the secret key used in production secret! 25 | SECRET_KEY = config("SECRET_KEY", default='') 26 | 27 | # SECURITY WARNING: don't run with debug turned on in production! 28 | DEBUG = config("DEBUG", default=True) 29 | 30 | ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='').split(',') 31 | 32 | if 'CODESPACE_NAME' in os.environ: 33 | codespace_name = config("CODESPACE_NAME") 34 | codespace_domain = config("GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN") 35 | CSRF_TRUSTED_ORIGINS = [f'https://{codespace_name}-8000.{codespace_domain}'] 36 | 37 | # Application definition 38 | 39 | INSTALLED_APPS = [ 40 | "django.contrib.admin", 41 | "django.contrib.auth", 42 | "django.contrib.contenttypes", 43 | "django.contrib.sessions", 44 | "django.contrib.messages", 45 | "django.contrib.staticfiles", 46 | "django_browser_reload", 47 | ] 48 | 49 | MIDDLEWARE = [ 50 | "django.middleware.security.SecurityMiddleware", 51 | "django.contrib.sessions.middleware.SessionMiddleware", 52 | "django.middleware.common.CommonMiddleware", 53 | "django.middleware.csrf.CsrfViewMiddleware", 54 | "django.contrib.auth.middleware.AuthenticationMiddleware", 55 | "django.contrib.messages.middleware.MessageMiddleware", 56 | "django.middleware.clickjacking.XFrameOptionsMiddleware", 57 | "django_browser_reload.middleware.BrowserReloadMiddleware", 58 | ] 59 | 60 | X_FRAME_OPTIONS = "ALLOW-FROM preview.app.github.dev" 61 | 62 | ROOT_URLCONF = "hello_world.urls" 63 | 64 | TEMPLATES = [ 65 | { 66 | "BACKEND": "django.template.backends.django.DjangoTemplates", 67 | "DIRS": [BASE_DIR / "hello_world" / "templates"], 68 | "APP_DIRS": True, 69 | "OPTIONS": { 70 | "context_processors": [ 71 | "django.template.context_processors.debug", 72 | "django.template.context_processors.request", 73 | "django.contrib.auth.context_processors.auth", 74 | "django.contrib.messages.context_processors.messages", 75 | ], 76 | }, 77 | }, 78 | ] 79 | 80 | WSGI_APPLICATION = "hello_world.wsgi.application" 81 | 82 | 83 | # Database 84 | # https://docs.djangoproject.com/en/5.0/ref/settings/#databases 85 | 86 | DATABASES = { 87 | "default": { 88 | "ENGINE": "django.db.backends.sqlite3", 89 | "NAME": BASE_DIR / "db.sqlite3", 90 | } 91 | } 92 | 93 | 94 | # Password validation 95 | # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators 96 | 97 | AUTH_PASSWORD_VALIDATORS = [ 98 | { 99 | "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", 100 | }, 101 | { 102 | "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", 103 | }, 104 | { 105 | "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", 106 | }, 107 | { 108 | "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", 109 | }, 110 | ] 111 | 112 | 113 | # Internationalization 114 | # https://docs.djangoproject.com/en/5.0/topics/i18n/ 115 | 116 | LANGUAGE_CODE = "en-us" 117 | 118 | TIME_ZONE = "UTC" 119 | 120 | USE_I18N = True 121 | 122 | USE_TZ = True 123 | 124 | 125 | # Static files (CSS, JavaScript, Images) 126 | # https://docs.djangoproject.com/en/5.0/howto/static-files/ 127 | 128 | STATICFILES_DIRS = [ 129 | BASE_DIR / "hello_world" / "static", 130 | ] 131 | 132 | STATIC_URL = "static/" 133 | STATIC_ROOT = BASE_DIR / "hello_world" / "staticfiles" 134 | 135 | MEDIA_URL = "media/" 136 | MEDIA_ROOT = BASE_DIR / "hello_world" / "media" 137 | 138 | 139 | # Default primary key field type 140 | # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field 141 | 142 | DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" 143 | -------------------------------------------------------------------------------- /hello_world/static/Octocat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/codespaces-django/3816b9147ddde21dc0e547c9496d1e29b6ee68df/hello_world/static/Octocat.png -------------------------------------------------------------------------------- /hello_world/static/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 4 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 12 | monospace; 13 | } 14 | 15 | .App { 16 | text-align: center; 17 | } 18 | 19 | .App-logo { 20 | height: 40vmin; 21 | pointer-events: none; 22 | } 23 | 24 | .App-header { 25 | background-color: #282c34; 26 | min-height: 100vh; 27 | display: flex; 28 | flex-direction: column; 29 | align-items: center; 30 | justify-content: center; 31 | font-size: calc(10px + 2vmin); 32 | color: white; 33 | } 34 | 35 | .App-link { 36 | color: #61dafb; 37 | } 38 | 39 | .heart { 40 | color: #ff0000; 41 | } 42 | 43 | .small { 44 | font-size: 0.75rem; 45 | } 46 | -------------------------------------------------------------------------------- /hello_world/templates/index.html: -------------------------------------------------------------------------------- 1 | {% load django_browser_reload %} 2 | {% load static %} 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |24 | GitHub Codespaces ♥️ Django 25 |
26 |
27 | Edit hello_world/templates/index.html
and see changes live!
28 |