-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e595c63
Showing
23 changed files
with
379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
venv | ||
*.pyc | ||
staticfiles | ||
.env | ||
db.sqlite3 | ||
getting-started/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn gettingstarted.wsgi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: python manage.py runserver 0.0.0.0:5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Django | ||
|
||
ما با استفاده از Django یک اپلیکیشن آزمایشی ساختهایم که میتوانید آن را روی کانتینر ابری قرار دهید. | ||
|
||
برای امتحان کردن این امکان، از ریپازیتوری Django در گیتهاب یک انشعاب بگیرید (Fork) تا یک نسخهی کپی از آن را روی ابرک خود داشته باشید. | ||
|
||
در مرحلهی بعد، با قرار دادن این ریپازیتوری به عنوان منبع، یک اپ بسازید. کانتینر ابری کد را بررسی خواهد کرد و به طور خودکار، اجزایی را که لازم است بسازد تشخیص خواهد داد. سپس، Buildpack مناسب را به کار خواهد برد تا یک کانتینر بسازد و دیپلوی کند. بعد از این قسمت، میتوانید تغییرات را روی انشعاب خود Push کنید و خواهید دید که کانتینر ابری به طور خودکار بهروزرسانیها را روی اپ شما مجددا اعمال خواهد کرد. | ||
|
||
## روش استفاده | ||
|
||
نسخهی پیشفرض پایتون در حال حاضر ۳.۹.۴ است. اگر میخواهید از نسخهی پایتون متفاوتی استفاده کنید، در ابتداییترین مرحلهی ریپازیتوری خود یک فایل `runtime.txt` بسازید و در یک خط کد، نسخهی پایتون مورد نظر خود را با فرمت `python-<MAJOR.MINOR.PATCH>` اضافه کنید. به عنوان مثال در صورت استفاده از پایتون ۳.۸.۸، `runtime.txt` | ||
شما به شکل زیر خواهد بود: | ||
|
||
``` | ||
python-3.8.8 | ||
``` | ||
|
||
## محدودیتها | ||
|
||
در صورت دیپلوی کردن دیپازیتوری Django در حالتی که از Gunicorn استفاده میشود، کانتینر ابری تنها بخشی از دستور اجرا را تشخیص خواهد داد. در این صورت لازم است شما به روش زیر نقطهی ورود (Entry Point) اپ خود را اضافه کنید: | ||
|
||
``` | ||
gunicorn --worker-tmp-dir /dev/shm mysite.wsgi. | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
""" | ||
Django settings for gettingstarted project. | ||
Generated by 'django-admin startproject' using Django 2.0. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/2.0/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/2.0/ref/settings/ | ||
""" | ||
|
||
import os | ||
import django_heroku | ||
|
||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = "CHANGE_ME!!!! (P.S. the SECRET_KEY environment variable will be used, if set, instead)." | ||
|
||
# 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", | ||
"hello", | ||
] | ||
|
||
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 = "gettingstarted.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 = "gettingstarted.wsgi.application" | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases | ||
|
||
DATABASES = { | ||
"default": { | ||
"ENGINE" : "django.db.backends.sqlite3", | ||
"NAME": os.path.join(BASE_DIR, "db.sqlite3") | ||
} | ||
} | ||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/2.0/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/2.0/topics/i18n/ | ||
|
||
LANGUAGE_CODE = "en-us" | ||
|
||
TIME_ZONE = "UTC" | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/2.0/howto/static-files/ | ||
|
||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') | ||
STATIC_URL = "/static/" | ||
|
||
django_heroku.settings(locals()) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.urls import path, include | ||
|
||
from django.contrib import admin | ||
|
||
admin.autodiscover() | ||
|
||
import hello.views | ||
|
||
# To add a new path, first import the app: | ||
# import blog | ||
# | ||
# Then add the new path: | ||
# path('blog/', blog.urls, name="blog") | ||
# | ||
# Learn more here: https://docs.djangoproject.com/en/2.1/topics/http/urls/ | ||
|
||
urlpatterns = [ | ||
path("", hello.views.index, name="index"), | ||
path("db/", hello.views.db, name="db"), | ||
path("admin/", admin.site.urls), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for gettingstarted project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gettingstarted.settings") | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
application = get_wsgi_application() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.1 on 2016-01-27 21:54 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Greeting', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('when', models.DateTimeField(auto_now_add=True, verbose_name=b'date created')), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.db import models | ||
|
||
# Create your models here. | ||
class Greeting(models.Model): | ||
when = models.DateTimeField("date created", auto_now_add=True) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="author" content="ArvanCloud"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"/> | ||
<title>Hello World</title> | ||
<link href='https://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'> | ||
<style> | ||
body { | ||
background-color: #00baba; | ||
font-family: Lato, Helvetica, sans-serif; | ||
color: #ffffff; | ||
height: 100vh; | ||
display: grid; | ||
place-items: center; | ||
font-weight: 400; | ||
} | ||
|
||
#banner { | ||
text-align: center; | ||
} | ||
|
||
.title { | ||
font-size: 4em; | ||
margin: 0; | ||
font-weight: 700; | ||
text-shadow: 4px 4px #1cafa5; | ||
} | ||
|
||
.title b { | ||
font-weight: 900; | ||
} | ||
|
||
.subtitle { | ||
font-weight: 300; | ||
font-size: 2em; | ||
margin: 2px 2px 32px; | ||
text-shadow: 2px 2px #1cafa5; | ||
} | ||
|
||
.subtitle b { | ||
font-weight: 400; | ||
} | ||
|
||
.btn { | ||
display: inline-block; | ||
color: white; | ||
text-decoration: none; | ||
border: 1px solid white; | ||
font-size: 2em; | ||
font-weight: 700; | ||
padding: 8px 24px; | ||
border-radius: 8px; | ||
transition: box-shadow 0.3s ease-in-out; | ||
} | ||
|
||
.btn.primary { | ||
border: none; | ||
background-color: #1c8c7e; | ||
} | ||
|
||
.btn:hover { | ||
box-shadow: 4px 4px #1cafa5; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
{% block content %}{% endblock %} | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
|
||
|
||
<h2>Page View Report</h2> | ||
|
||
|
||
<ul> | ||
|
||
{% for greeting in greetings %} | ||
<li>{{ greeting.when }}</li> | ||
{% endfor %} | ||
|
||
</ul> | ||
|
||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
|
||
{% block content %} | ||
|
||
<div id="banner"> | ||
<h1 class="title">Hello From <b>ArvanCloud</b></h1> | ||
<div class="subtitle">This is a sample <b>Django</b> application deployed to <b>ArvanCloud</b>.</div> | ||
<div> | ||
<a href="https://github.com/arvancloud/paas-django-sample" target="_blank" class="btn primary">Source Code</a> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.contrib.auth.models import AnonymousUser, User | ||
from django.test import TestCase, RequestFactory | ||
|
||
from .views import index | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def setUp(self): | ||
# Every test needs access to the request factory. | ||
self.factory = RequestFactory() | ||
|
||
def test_details(self): | ||
# Create an instance of a GET request. | ||
request = self.factory.get("/") | ||
request.user = AnonymousUser() | ||
|
||
# Test my_view() as if it were deployed at /customer/details | ||
response = index(request) | ||
self.assertEqual(response.status_code, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpResponse | ||
|
||
from .models import Greeting | ||
|
||
# Create your views here. | ||
def index(request): | ||
# return HttpResponse('Hello from Python!') | ||
return render(request, "index.html") | ||
|
||
|
||
def db(request): | ||
|
||
greeting = Greeting() | ||
greeting.save() | ||
|
||
greetings = Greeting.objects.all() | ||
|
||
return render(request, "db.html", {"greetings": greetings}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gettingstarted.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
django | ||
gunicorn | ||
django-heroku |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-3.10.1 |