Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/django/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.py
*.DotSettings.user
19 changes: 19 additions & 0 deletions examples/django/Django.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<WarnOn>3390;$(WarnOn)</WarnOn>
</PropertyGroup>
<ItemGroup>
<Compile Include="tproj/Wsgi.fs" />
<Compile Include="tproj/Urls.fs" />
<Compile Include="tproj/Asgi.fs" />
<Compile Include="tproj/Settings.fs" />
<Compile Include="Manage.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fable.Python" Version="0.12.0" />
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-005" />
</ItemGroup>
</Project>
26 changes: 26 additions & 0 deletions examples/django/Manage.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python

module Django.Manage

//Django command-line utility for administrative tasks.

open Fable.Core
open Fable.Core.PyInterop

type IEnviron =
[<Emit("$0.setdefault($1,$2)")>]
abstract setdefault : string * string -> unit

[<ImportMember("os")>]
let environ: IEnviron = nativeOnly

[<ImportAll("sys")>]
let sys : obj = nativeOnly

[<ImportMember("django.core.management")>]
let execute_from_command_line: string [] -> int = nativeOnly

[<EntryPoint>]
let main argv =
environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings")
execute_from_command_line sys?argv
31 changes: 31 additions & 0 deletions examples/django/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Fable Python on Django

## Info

The project is a copy of Django's `python manage.py startproject tproj` output.
The compiled version should be almost identical to the above command.


## Install Dependencies

```sh
> dotnet tool restore
> dotnet restore

> pip3 install -r Django
```

## Build

```
> dotnet fable-py
```

## Run

```sh
> python3 manage.py runserver
```

Visit http://127.0.0.1:8000/

1 change: 1 addition & 0 deletions examples/django/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Django>=3.2.8,<4.0.0
26 changes: 26 additions & 0 deletions examples/django/tproj/Asgi.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Django.tproj.Asgi

open Fable.Core
//ASGI config for testproj project.
//
//It exposes the ASGI callable as a module-level variable named ``application``.
//
//For more information on this file, see
//https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/

type IEnviron =
[<Emit("$0.setdefault($1,$2)")>]
abstract setdefault : string * string -> unit

[<ImportMember("os")>]
let environ: IEnviron = nativeOnly

type IASGI =
[<Emit("$0.get_asgi_application()")>]
abstract get_asgi_application: unit -> unit

[<ImportMember("django.core")>]
let asgi: IASGI= nativeOnly

environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings")
let application = asgi.get_asgi_application()
131 changes: 131 additions & 0 deletions examples/django/tproj/Settings.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
module Django.tproj.Settings

open Fable.Core
open Fable.Core.PyInterop
open Fable.Python

//Django settings for tproj project.
//
//Generated by "django-admin startproject " using Django 3.2.8.
//
//For more information on this file, see
//https://docs.djangoproject.com/en/3.2/topics/settings/
//
//For the full list of settings and their values, see
//https://docs.djangoproject.com/en/3.2/ref/settings/


[<Emit("__file__")>]
let __file__: string = nativeOnly

[<ImportMember("pathlib")>]
let Path: string -> obj = nativeOnly

// Build paths inside the project like this: BASE_DIR / "subdir ".
let BASE_DIR:string = string (Path(__file__)?resolve()?parent?parent)

// Quick-start development settings - unsuitable for production
// See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
//
// SECURITY WARNING: keep the secret key used in production secret!
let SECRET_KEY = "django-insecure-8@-!^t#jw8svblg!%z5meh+#48nvd)me-*^im))uvy6pfweb"
//
// SECURITY WARNING: don "t run with debug turned on in production!
let DEBUG = true

let ALLOWED_HOSTS: string[] = [||]


// Application definition
//
let INSTALLED_APPS = [|
"django.contrib.admin"
"django.contrib.auth"
"django.contrib.contenttypes"
"django.contrib.sessions"
"django.contrib.messages"
"django.contrib.staticfiles"
|]

let 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"
|]

let ROOT_URLCONF = "tproj.urls"

let TEMPLATES: {| APP_DIRS: bool; BACKEND: string; DIRS: string []; OPTIONS: {| context_processors: string [] |} |} [] =
[|
{| 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"
|]
|}

|}
|]

let WSGI_APPLICATION = "tproj.wsgi.application"

// Database
// https://docs.djangoproject.com/en/3.2/ref/settings/#databases

let DATABASES = {|
``default``= {|
ENGINE="django.db.backends.sqlite3"
NAME = BASE_DIR + "/db.sqlite3"
|}
|}

// Password validation
// https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

let 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/3.2/topics/i18n/

let LANGUAGE_CODE = "en-us"

let TIME_ZONE = "UTC"

let USE_I18N = true

let USE_L10N = true

let USE_TZ = true

// Static files (CSS, JavaScript, Images)
// https://docs.djangoproject.com/en/3.2/howto/static-files/

let STATIC_URL = "/static/"

// Default primary key field type
// https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

let DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
31 changes: 31 additions & 0 deletions examples/django/tproj/Urls.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Django.tproj.Urls

open Fable.Core
open Fable.Core.PyInterop

//tproj URL Configuration
//
//The `urlpatterns` list routes URLs to views. For more information please see:
// https://docs.djangoproject.com/en/3.2/topics/http/urls/
//Examples:
//Function views
// 1. Add an import: from my_app import views
// 2. Add a URL to urlpatterns: path('', views.home, name='home')
//Class-based views
// 1. Add an import: from other_app.views import Home
// 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
//Including another URLconf
// 1. Import the include() function: from django.urls import include, path
// 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))

[<ImportMember("django.contrib")>]
let admin: obj = nativeOnly

type IPath =
abstract path : url: string * view: obj -> obj

[<ImportMember("django")>]
let urls: IPath = nativeOnly
let urlpatterns = [|
urls.path("admin/", admin?site?urls)
|]
28 changes: 28 additions & 0 deletions examples/django/tproj/Wsgi.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Django.tproj.Wsgi

open Fable.Core
//WSGI config for testproj 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/3.2/howto/deployment/wsgi/



type IEnviron =
[<Emit("$0.setdefault($1,$2)")>]
abstract setdefault : string * string -> unit

[<ImportMember("os")>]
let environ: IEnviron = nativeOnly

type IWSGI =
[<Emit("$0.get_wsgi_application()")>]
abstract get_wsgi_application: unit -> unit

[<ImportMember("django.core")>]
let wsgi: IWSGI= nativeOnly

environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings")
let application = wsgi.get_wsgi_application()