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
1 change: 1 addition & 0 deletions examples/django-minimal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py
15 changes: 15 additions & 0 deletions examples/django-minimal/DjangoMinimal.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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="Program.fs"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fable.Python" Version="0.12.0"/>
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-005"/>
</ItemGroup>
</Project>
51 changes: 51 additions & 0 deletions examples/django-minimal/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
module Program

open System
open System.Collections.Generic
open Fable.Core
open Fable.Python
open Fable.Core.PyInterop

type ISettings =
[<Emit("$0.configure(DEBUG=$1, ROOT_URLCONF=$2)")>]
abstract configure : DEBUG: bool * ROOT_URLCONF : obj -> unit


[<ImportMember("django.conf")>]
let settings: ISettings = nativeOnly
type IPath =
abstract path : url: string * view: obj -> obj

[<ImportMember("django")>]
let urls: IPath = nativeOnly


[<ImportMember("django.http")>]
let HttpResponse: string -> obj = nativeOnly


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

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

[<Emit("sys.modules[__name__]")>]
let sysModules : unit -> obj = nativeOnly

settings.configure (
DEBUG=true,
ROOT_URLCONF = sysModules
)

let index request =
HttpResponse("<h1>A minimal Django response!</h1>")

let urlpatterns = [|
urls.path ("",index)
|]

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

A minimal example (single file).

## Credits

https://github.com/rnevius/minimal-django

## Install Dependencies

```sh
> dotnet tool restore
> dotnet restore

> pip3 install -r requirements.txt
```

## Build

```
> dotnet fable-py
```

## Run

```sh
> python3 program.py runserver
```

Visit http://127.0.0.1:8000/

1 change: 1 addition & 0 deletions examples/django-minimal/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Django>=3.2.8,<4.0.0