Skip to content

Commit e0512a5

Browse files
committed
Added django minimal example
1 parent 35aac3a commit e0512a5

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

examples/django-minimal/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.py
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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="Program.fs"/>
10+
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Fable.Python" Version="0.12.0"/>
13+
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-005"/>
14+
</ItemGroup>
15+
</Project>

examples/django-minimal/Program.fs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
2+
module Program
3+
4+
open System
5+
open System.Collections.Generic
6+
open Fable.Core
7+
open Fable.Python
8+
open Fable.Core.PyInterop
9+
10+
type ISettings =
11+
[<Emit("$0.configure(DEBUG=$1, ROOT_URLCONF=$2)")>]
12+
abstract configure : DEBUG: bool * ROOT_URLCONF : obj -> unit
13+
14+
15+
[<ImportMember("django.conf")>]
16+
let settings: ISettings = nativeOnly
17+
type IPath =
18+
abstract path : url: string * view: obj -> obj
19+
20+
[<ImportMember("django")>]
21+
let urls: IPath = nativeOnly
22+
23+
24+
[<ImportMember("django.http")>]
25+
let HttpResponse: string -> obj = nativeOnly
26+
27+
28+
[<ImportMember("django.core.management")>]
29+
let execute_from_command_line: string [] -> int = nativeOnly
30+
31+
[<Emit("sys.modules[__name__]")>]
32+
let sysModules : unit -> obj = nativeOnly
33+
34+
settings.configure (
35+
DEBUG=true,
36+
ROOT_URLCONF = sysModules
37+
)
38+
39+
let index request =
40+
HttpResponse("<h1>A minimal Django response!</h1>")
41+
42+
let urlpatterns = [|
43+
urls.path ("",index)
44+
|]
45+
46+
[<EntryPoint>]
47+
let main argv =
48+
execute_from_command_line (argv)

examples/django-minimal/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Fable Python on Django
2+
3+
A minimal example (single file).
4+
5+
## Credits
6+
7+
https://github.com/rnevius/minimal-django
8+
9+
## Install Dependencies
10+
11+
```sh
12+
> dotnet tool restore
13+
> dotnet restore
14+
15+
> pip install -r Django
16+
```
17+
18+
## Build
19+
20+
```
21+
> dotnet fable-py
22+
```
23+
24+
## Run
25+
26+
Note that the first argument is skipped, because of `main(sys.argv[1:])` for some reason
27+
```sh
28+
> python3 program.py skipped runserver
29+
```
30+
31+
Visit http://127.0.0.1:8000/
32+
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

0 commit comments

Comments
 (0)