Skip to content

Commit 7762fe7

Browse files
authored
Merge pull request #9 from delneg/django-minimal
Django minimal example
2 parents 711db21 + 7b12ae0 commit 7762fe7

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
[<ImportAll("sys")>]
32+
let sys : obj = nativeOnly
33+
34+
[<Emit("sys.modules[__name__]")>]
35+
let sysModules : unit -> obj = nativeOnly
36+
37+
settings.configure (
38+
DEBUG=true,
39+
ROOT_URLCONF = sysModules
40+
)
41+
42+
let index request =
43+
HttpResponse("<h1>A minimal Django response!</h1>")
44+
45+
let urlpatterns = [|
46+
urls.path ("",index)
47+
|]
48+
49+
[<EntryPoint>]
50+
let main argv =
51+
execute_from_command_line (sys?argv)

examples/django-minimal/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+
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+
> pip3 install -r requirements.txt
16+
```
17+
18+
## Build
19+
20+
```
21+
> dotnet fable-py
22+
```
23+
24+
## Run
25+
26+
```sh
27+
> python3 program.py runserver
28+
```
29+
30+
Visit http://127.0.0.1:8000/
31+
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)