├── .gitignore ├── Djangodeployexample.png ├── README.md ├── requirements.txt └── src ├── hello_world ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ └── __init__.py ├── models.py ├── tests.py └── views.py ├── manage.py └── proj ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | 137 | # Cython debug symbols 138 | cython_debug/ -------------------------------------------------------------------------------- /Djangodeployexample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvk-net/django-dummy/04e0a734fc6a1fb4dbc07d03e7674ceb504c9d7d/Djangodeployexample.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dummy hello world Django app 2 | 3 | # Webapp deploy to www.pythonanywhere.com 4 | # [Video Instruction](https://youtu.be/D-3xTYR1vBc) 5 | ![img](Djangodeployexample.png) 6 | 1. Visit and register [https://www.pythonanywhere.com/](https://www.pythonanywhere.com/) 7 | 2. Push your project to github 8 | 1. Start `bash console` at pythonanywhere 9 | 1. Git clone your project to pythonanywhere 10 | 1. Create `virtual env` 11 | 1. cd to clonned project dir 12 | 1. 13 | ```sh 14 | python3 -m venv env 15 | ``` 16 | 17 | 1. Activate `venv` and install all dependencies 18 | 1. Create `new custom webapp` at pythonanywhere 19 | 1. Fill in all the gaps 20 | 1. Source code: - the path to the folder with `manage.py` (/home/denniskot/django-dummy/src) 21 | 1. Virtualenv: 22 | 1. The path to the folder with virtual env (`/home/denniskot/django-dummy/env`) 23 | 1. Static files: 24 | 1. Create in bash conslole folders `static` and `media` on the same level as `src` folder. (/home/denniskot/django-dummy/static and /home/denniskot/django-dummy/media) 25 | 1. Add url `/static/` and directory `/home/denniskot/django-dummy/static` 26 | 1. Add url `/media/` and directory `/home/denniskot/django-dummy/media` 27 | 1. `Edit WSGI configuration file` (click the link) 28 | 1. Comment "hello world" section 29 | 2. Find "django" section 30 | 1. Comment out django section 31 | 1. Change `path` to the folder with your 'manage.py' file (`/home/denniskot/django-dummy/src`) 32 | 1. Change `os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'` 33 | where `mysite` is the project/module/folder name with 'settings.py' file 34 | (`os.environ['DJANGO_SETTINGS_MODULE'] = 'proj.settings'`) 35 | 36 | ```python 37 | # My WSGI file 38 | # +++++++++++ DJANGO +++++++++++ 39 | # To use your own django app use code like this: 40 | import os 41 | import sys 42 | 43 | # assuming your django settings file is at '/home/denniskot/mysite/mysite/settings.py' 44 | # and your manage.py is is at '/home/denniskot/mysite/manage.py' 45 | path = '/home/denniskot/django-dummy/src' 46 | if path not in sys.path: 47 | sys.path.append(path) 48 | 49 | os.environ['DJANGO_SETTINGS_MODULE'] = 'proj.settings' 50 | 51 | # then: 52 | from django.core.wsgi import get_wsgi_application 53 | application = get_wsgi_application() 54 | ``` 55 | 1. Edit settings.py 56 | 1. edit 57 | ```python 58 | ALLOWED_HOSTS = ['yourloginname.pythonanywhere.com',] 59 | ``` 60 | 2. add lines below STATIC_URL 61 | ```python 62 | # Change path in *_ROOT according to your static and media path 63 | MEDIA_URL = '/media/' 64 | STATIC_ROOT = '/home/denniskot/django-dummy/static' 65 | MEDIA_ROOT = '/home/denniskot/django-dummy/media' 66 | 67 | 1. reload webapp 68 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.2.10 2 | Django==3.1.2 3 | pytz==2020.1 4 | sqlparse==0.4.1 5 | -------------------------------------------------------------------------------- /src/hello_world/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvk-net/django-dummy/04e0a734fc6a1fb4dbc07d03e7674ceb504c9d7d/src/hello_world/__init__.py -------------------------------------------------------------------------------- /src/hello_world/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /src/hello_world/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HelloWorldConfig(AppConfig): 5 | name = 'hello_world' 6 | -------------------------------------------------------------------------------- /src/hello_world/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvk-net/django-dummy/04e0a734fc6a1fb4dbc07d03e7674ceb504c9d7d/src/hello_world/migrations/__init__.py -------------------------------------------------------------------------------- /src/hello_world/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /src/hello_world/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /src/hello_world/views.py: -------------------------------------------------------------------------------- 1 | import random 2 | from django.shortcuts import render 3 | from django.http import HttpResponse 4 | # Create your views here. 5 | 6 | def hello_world(request): 7 | result = random.randint(1, 100) 8 | return HttpResponse(f"Hello world!!! With random int - {result}") 9 | -------------------------------------------------------------------------------- /src/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /src/proj/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvk-net/django-dummy/04e0a734fc6a1fb4dbc07d03e7674ceb504c9d7d/src/proj/__init__.py -------------------------------------------------------------------------------- /src/proj/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for proj 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/3.1/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', 'proj.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /src/proj/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for proj project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'sc^0w2(hxpsa)4t4ij7&l)6$%w=&m^=ot@@5(ezk4$ol0-5v91' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'hello_world' 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'proj.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'proj.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'ru-ru' 108 | 109 | TIME_ZONE = 'Europe/Minsk' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | 124 | VASILY = "Василий" -------------------------------------------------------------------------------- /src/proj/urls.py: -------------------------------------------------------------------------------- 1 | """proj URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | from hello_world.views import hello_world 20 | 21 | urlpatterns = [ 22 | path('admin/', admin.site.urls), 23 | path('hello-world/', hello_world) 24 | ] 25 | -------------------------------------------------------------------------------- /src/proj/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for proj project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') 15 | 16 | application = get_wsgi_application() 17 | --------------------------------------------------------------------------------