Skip to content

Commit 9d48bce

Browse files
committed
Added django startproject example
1 parent 35aac3a commit 9d48bce

File tree

9 files changed

+295
-0
lines changed

9 files changed

+295
-0
lines changed

examples/django/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.py
2+
*.DotSettings.user

examples/django/Django.fsproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<WarnOn>3390;$(WarnOn)</WarnOn>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Compile Include="tproj/Wsgi.fs" />
10+
<Compile Include="tproj/Urls.fs" />
11+
<Compile Include="tproj/Asgi.fs" />
12+
<Compile Include="tproj/Settings.fs" />
13+
<Compile Include="Manage.fs" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<PackageReference Include="Fable.Python" Version="0.12.0" />
17+
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-005" />
18+
</ItemGroup>
19+
</Project>

examples/django/Manage.fs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
module Django.Manage
4+
5+
//Django command-line utility for administrative tasks.
6+
7+
open Fable.Core
8+
open Fable.Core.PyInterop
9+
10+
type IEnviron =
11+
[<Emit("$0.setdefault($1,$2)")>]
12+
abstract setdefault : string * string -> unit
13+
14+
[<ImportMember("os")>]
15+
let environ: IEnviron = nativeOnly
16+
17+
[<ImportAll("sys")>]
18+
let sys : obj = nativeOnly
19+
20+
[<ImportMember("django.core.management")>]
21+
let execute_from_command_line: string [] -> int = nativeOnly
22+
23+
[<EntryPoint>]
24+
let main argv =
25+
environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings")
26+
execute_from_command_line sys?argv

examples/django/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Fable Python on Django
2+
3+
## Info
4+
5+
The project is a copy of Django's `python manage.py startproject tproj` output.
6+
The compiled version should be almost identical to the above command.
7+
8+
9+
## Install Dependencies
10+
11+
```sh
12+
> dotnet tool restore
13+
> dotnet restore
14+
15+
> pip3 install -r Django
16+
```
17+
18+
## Build
19+
20+
```
21+
> dotnet fable-py
22+
```
23+
24+
## Run
25+
26+
```sh
27+
> python3 manage.py runserver
28+
```
29+
30+
Visit http://127.0.0.1:8000/
31+

examples/django/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Django>=3.2.8,<4.0.0

examples/django/tproj/Asgi.fs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Django.tproj.Asgi
2+
3+
open Fable.Core
4+
//ASGI config for testproj project.
5+
//
6+
//It exposes the ASGI callable as a module-level variable named ``application``.
7+
//
8+
//For more information on this file, see
9+
//https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
10+
11+
type IEnviron =
12+
[<Emit("$0.setdefault($1,$2)")>]
13+
abstract setdefault : string * string -> unit
14+
15+
[<ImportMember("os")>]
16+
let environ: IEnviron = nativeOnly
17+
18+
type IASGI =
19+
[<Emit("$0.get_asgi_application()")>]
20+
abstract get_asgi_application: unit -> unit
21+
22+
[<ImportMember("django.core")>]
23+
let asgi: IASGI= nativeOnly
24+
25+
environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings")
26+
let application = asgi.get_asgi_application()

examples/django/tproj/Settings.fs

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
module Django.tproj.Settings
2+
3+
open Fable.Core
4+
open Fable.Core.PyInterop
5+
open Fable.Python
6+
7+
//Django settings for tproj project.
8+
//
9+
//Generated by "django-admin startproject " using Django 3.2.8.
10+
//
11+
//For more information on this file, see
12+
//https://docs.djangoproject.com/en/3.2/topics/settings/
13+
//
14+
//For the full list of settings and their values, see
15+
//https://docs.djangoproject.com/en/3.2/ref/settings/
16+
17+
18+
[<Emit("__file__")>]
19+
let __file__: string = nativeOnly
20+
21+
[<ImportMember("pathlib")>]
22+
let Path: string -> obj = nativeOnly
23+
24+
// Build paths inside the project like this: BASE_DIR / "subdir ".
25+
let BASE_DIR:string = string (Path(__file__)?resolve()?parent?parent)
26+
27+
// Quick-start development settings - unsuitable for production
28+
// See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
29+
//
30+
// SECURITY WARNING: keep the secret key used in production secret!
31+
let SECRET_KEY = "django-insecure-8@-!^t#jw8svblg!%z5meh+#48nvd)me-*^im))uvy6pfweb"
32+
//
33+
// SECURITY WARNING: don "t run with debug turned on in production!
34+
let DEBUG = true
35+
36+
let ALLOWED_HOSTS: string[] = [||]
37+
38+
39+
// Application definition
40+
//
41+
let INSTALLED_APPS = [|
42+
"django.contrib.admin"
43+
"django.contrib.auth"
44+
"django.contrib.contenttypes"
45+
"django.contrib.sessions"
46+
"django.contrib.messages"
47+
"django.contrib.staticfiles"
48+
|]
49+
50+
let MIDDLEWARE = [|
51+
"django.middleware.security.SecurityMiddleware"
52+
"django.contrib.sessions.middleware.SessionMiddleware"
53+
"django.middleware.common.CommonMiddleware"
54+
"django.middleware.csrf.CsrfViewMiddleware"
55+
"django.contrib.auth.middleware.AuthenticationMiddleware"
56+
"django.contrib.messages.middleware.MessageMiddleware"
57+
"django.middleware.clickjacking.XFrameOptionsMiddleware"
58+
|]
59+
60+
let ROOT_URLCONF = "tproj.urls"
61+
62+
let TEMPLATES: {| APP_DIRS: bool; BACKEND: string; DIRS: string []; OPTIONS: {| context_processors: string [] |} |} [] =
63+
[|
64+
{| BACKEND = "django.template.backends.django.DjangoTemplates"
65+
DIRS= [||]
66+
APP_DIRS = true
67+
OPTIONS ={|
68+
context_processors=
69+
[|
70+
"django.template.context_processors.debug"
71+
"django.template.context_processors.request"
72+
"django.contrib.auth.context_processors.auth"
73+
"django.contrib.messages.context_processors.messages"
74+
|]
75+
|}
76+
77+
|}
78+
|]
79+
80+
let WSGI_APPLICATION = "tproj.wsgi.application"
81+
82+
// Database
83+
// https://docs.djangoproject.com/en/3.2/ref/settings/#databases
84+
85+
let DATABASES = {|
86+
``default``= {|
87+
ENGINE="django.db.backends.sqlite3"
88+
NAME = BASE_DIR + "/db.sqlite3"
89+
|}
90+
|}
91+
92+
// Password validation
93+
// https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
94+
95+
let AUTH_PASSWORD_VALIDATORS = [|
96+
{|
97+
NAME="django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
98+
|}
99+
{|
100+
NAME="django.contrib.auth.password_validation.MinimumLengthValidator"
101+
|}
102+
{|
103+
NAME="django.contrib.auth.password_validation.CommonPasswordValidator"
104+
|}
105+
{|
106+
NAME="django.contrib.auth.password_validation.NumericPasswordValidator"
107+
|}
108+
|]
109+
110+
// Internationalization
111+
// https://docs.djangoproject.com/en/3.2/topics/i18n/
112+
113+
let LANGUAGE_CODE = "en-us"
114+
115+
let TIME_ZONE = "UTC"
116+
117+
let USE_I18N = true
118+
119+
let USE_L10N = true
120+
121+
let USE_TZ = true
122+
123+
// Static files (CSS, JavaScript, Images)
124+
// https://docs.djangoproject.com/en/3.2/howto/static-files/
125+
126+
let STATIC_URL = "/static/"
127+
128+
// Default primary key field type
129+
// https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
130+
131+
let DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

examples/django/tproj/Urls.fs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Django.tproj.Urls
2+
3+
open Fable.Core
4+
open Fable.Core.PyInterop
5+
6+
//tproj URL Configuration
7+
//
8+
//The `urlpatterns` list routes URLs to views. For more information please see:
9+
// https://docs.djangoproject.com/en/3.2/topics/http/urls/
10+
//Examples:
11+
//Function views
12+
// 1. Add an import: from my_app import views
13+
// 2. Add a URL to urlpatterns: path('', views.home, name='home')
14+
//Class-based views
15+
// 1. Add an import: from other_app.views import Home
16+
// 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
17+
//Including another URLconf
18+
// 1. Import the include() function: from django.urls import include, path
19+
// 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
20+
21+
[<ImportMember("django.contrib")>]
22+
let admin: obj = nativeOnly
23+
24+
type IPath =
25+
abstract path : url: string * view: obj -> obj
26+
27+
[<ImportMember("django")>]
28+
let urls: IPath = nativeOnly
29+
let urlpatterns = [|
30+
urls.path("admin/", admin?site?urls)
31+
|]

examples/django/tproj/Wsgi.fs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Django.tproj.Wsgi
2+
3+
open Fable.Core
4+
//WSGI config for testproj project.
5+
//
6+
//It exposes the WSGI callable as a module-level variable named ``application``.
7+
//
8+
//For more information on this file, see
9+
//https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
10+
11+
12+
13+
type IEnviron =
14+
[<Emit("$0.setdefault($1,$2)")>]
15+
abstract setdefault : string * string -> unit
16+
17+
[<ImportMember("os")>]
18+
let environ: IEnviron = nativeOnly
19+
20+
type IWSGI =
21+
[<Emit("$0.get_wsgi_application()")>]
22+
abstract get_wsgi_application: unit -> unit
23+
24+
[<ImportMember("django.core")>]
25+
let wsgi: IWSGI= nativeOnly
26+
27+
environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings")
28+
let application = wsgi.get_wsgi_application()

0 commit comments

Comments
 (0)