Leaderboard
Popular Content
Showing content with the highest reputation on 10/02/2022 in all areas
-
We will update our wiki article on how to get started with Django, but just posting a quick example here so people can comment and ask questions on this thread. Create a directory on your main domain called djangotest. If you were transferred from cPanel your main domain will be parked on the public_html directory. If you created a new account on Plesk your directory will be httpdocs. Create an .htaccess file inside the djangotest directory with these contents: Options +ExecCGI RewriteEngine On RewriteBase / RewriteRule ^(media/.*)$ - [L] RewriteRule ^(admin_media/.*)$ - [L] RewriteRule ^(djangotest/dispatch\.wsgi/.*)$ - [L] RewriteRule ^(.*)$ djangotest/djangotest/dispatch.wsgi/$1 [QSA,PT,L] Next create another djangotest directory within the first djangotest directory. This is the standard directory structure for a Django project so don't give me that look. I'm sure they did it on purpose just to make it more confusing for you. Also you can't name your Django project django either, so don't even bother trying. That's why we're calling this example djangotest. Inside the second djangotest directory make a file named dispatch.wsgi with these contents: import os, sys # edit path below sys.path.append("/home/domain.helioho.st/httpdocs/djangotest") from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangotest.settings') application = get_wsgi_application() Make sure you edit the path in the dispatch.wsgi file. On Plesk your path is /home/ and then your main domain, and then httpdocs if you're a new account or public_html if you've been transferred from cPanel. Inside the second djangotest directory create an empty file named __init__.py Inside the second djangotest directory make a file named urls.py with these contents: from django.contrib import admin from django.urls import path urlpatterns = [ # path('admin/', admin.site.urls), ] Inside the second djangotest directory make a file named settings.py with these contents: from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-makeyoursecretbetterthanthis' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['*'] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'djangotest.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'djangotest.wsgi.application' # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } # Password validation # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.1/howto/static-files/ STATIC_URL = 'static/' # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' Make sure your directory structure and files look like this: djangotest/ ├── djangotest │ ├── dispatch.wsgi │ ├── __init__.py │ ├── settings.py │ └── urls.py └── .htaccess 1 directory, 5 files If you did everything right it should look like this: https://krydos.heliohost.org/djangotest/1 point
-
Django 4.1.1 and Flask 2.2.2 have been installed on Tommy's Python 3.10. We will update the wiki eventually, but for now there are some quick guides on the forums to get you started. If you have any questions or comments please let us know.1 point