<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: radiac</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/radiac.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2024-09-24T16:08:44+00:00</updated><author><name>Simon Willison</name></author><entry><title>nanodjango</title><link href="https://simonwillison.net/2024/Sep/24/nanodjango/" rel="alternate"/><published>2024-09-24T16:08:44+00:00</published><updated>2024-09-24T16:08:44+00:00</updated><id>https://simonwillison.net/2024/Sep/24/nanodjango/</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/radiac/nanodjango"&gt;nanodjango&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Richard Terry demonstrated this in a lightning talk at DjangoCon US today. It's the latest in a long line of attempts to get Django to work with a single file (I had a go at this problem 15 years ago with &lt;a href="https://github.com/simonw/djng"&gt;djng&lt;/a&gt;) but this one is &lt;em&gt;really&lt;/em&gt; compelling.&lt;/p&gt;
&lt;p&gt;I tried nanodjango out just now and it works exactly as advertised. First install it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install nanodjango
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a &lt;code&gt;counter.py&lt;/code&gt; file:&lt;/p&gt;
&lt;pre&gt;&lt;span class="pl-k"&gt;from&lt;/span&gt; &lt;span class="pl-s1"&gt;django&lt;/span&gt;.&lt;span class="pl-s1"&gt;db&lt;/span&gt; &lt;span class="pl-k"&gt;import&lt;/span&gt; &lt;span class="pl-s1"&gt;models&lt;/span&gt;
&lt;span class="pl-k"&gt;from&lt;/span&gt; &lt;span class="pl-s1"&gt;nanodjango&lt;/span&gt; &lt;span class="pl-k"&gt;import&lt;/span&gt; &lt;span class="pl-v"&gt;Django&lt;/span&gt;

&lt;span class="pl-s1"&gt;app&lt;/span&gt; &lt;span class="pl-c1"&gt;=&lt;/span&gt; &lt;span class="pl-v"&gt;Django&lt;/span&gt;()

&lt;span class="pl-en"&gt;@&lt;span class="pl-s1"&gt;app&lt;/span&gt;.&lt;span class="pl-s1"&gt;admin&lt;/span&gt; &lt;span class="pl-c"&gt;# Registers with the Django admin&lt;/span&gt;&lt;/span&gt;
&lt;span class="pl-k"&gt;class&lt;/span&gt; &lt;span class="pl-v"&gt;CountLog&lt;/span&gt;(&lt;span class="pl-s1"&gt;models&lt;/span&gt;.&lt;span class="pl-v"&gt;Model&lt;/span&gt;):
    &lt;span class="pl-s1"&gt;timestamp&lt;/span&gt; &lt;span class="pl-c1"&gt;=&lt;/span&gt; &lt;span class="pl-s1"&gt;models&lt;/span&gt;.&lt;span class="pl-v"&gt;DateTimeField&lt;/span&gt;(&lt;span class="pl-s1"&gt;auto_now_add&lt;/span&gt;&lt;span class="pl-c1"&gt;=&lt;/span&gt;&lt;span class="pl-c1"&gt;True&lt;/span&gt;)

&lt;span class="pl-en"&gt;@&lt;span class="pl-s1"&gt;app&lt;/span&gt;.&lt;span class="pl-en"&gt;route&lt;/span&gt;(&lt;span class="pl-s"&gt;"/"&lt;/span&gt;)&lt;/span&gt;
&lt;span class="pl-k"&gt;def&lt;/span&gt; &lt;span class="pl-en"&gt;count&lt;/span&gt;(&lt;span class="pl-s1"&gt;request&lt;/span&gt;):
    &lt;span class="pl-v"&gt;CountLog&lt;/span&gt;.&lt;span class="pl-s1"&gt;objects&lt;/span&gt;.&lt;span class="pl-en"&gt;create&lt;/span&gt;()
    &lt;span class="pl-k"&gt;return&lt;/span&gt; &lt;span class="pl-s"&gt;f"&amp;lt;p&amp;gt;Number of page loads: &lt;span class="pl-s1"&gt;&lt;span class="pl-kos"&gt;{&lt;/span&gt;&lt;span class="pl-v"&gt;CountLog&lt;/span&gt;.&lt;span class="pl-s1"&gt;objects&lt;/span&gt;.&lt;span class="pl-en"&gt;count&lt;/span&gt;()&lt;span class="pl-kos"&gt;}&lt;/span&gt;&lt;/span&gt;&amp;lt;/p&amp;gt;"&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Then run it like this (it will run migrations and create a superuser as part of that first run):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nanodjango run counter.py
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's it! This gave me a fully configured Django application with models, migrations, the Django Admin configured and a bunch of other goodies such as &lt;a href="https://django-ninja.dev/"&gt;Django Ninja&lt;/a&gt; for API endpoints.&lt;/p&gt;
&lt;p&gt;Here's the &lt;a href="https://nanodjango.readthedocs.io/"&gt;full documentation&lt;/a&gt;.


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/django"&gt;django&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/django-admin"&gt;django-admin&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/radiac"&gt;radiac&lt;/a&gt;&lt;/p&gt;



</summary><category term="django"/><category term="django-admin"/><category term="python"/><category term="radiac"/></entry><entry><title>Have a webby Christmas</title><link href="https://simonwillison.net/2005/Dec/1/webby/" rel="alternate"/><published>2005-12-01T13:24:07+00:00</published><updated>2005-12-01T13:24:07+00:00</updated><id>https://simonwillison.net/2005/Dec/1/webby/</id><summary type="html">
    &lt;p id="p-0"&gt;Sadly there's no &lt;a href="http://www.perladvent.org/"&gt;Perl Advent Calendar&lt;/a&gt; this year, but the slack has been picked up by Drew McLellan's &lt;a href="http://24ways.org/"&gt;24 ways&lt;/a&gt; to impress your friends - a neat web development tip every day until Christmas.&lt;/p&gt;

&lt;p id="p-1"&gt;&lt;a href="http://lazyweb.org/"&gt;Lazyweb&lt;/a&gt; request: 24 ways is currently devoid of baubles, reindeer, animated doors and DHTML snowflakes. Someone needs to write a Greasemonkey script (now &lt;a href="http://greaseblog.blogspot.com/2005/11/greasemonkey-064_30.html" title="Greasemonkey 0.6.4"&gt;Firefox 1.5 compatible&lt;/a&gt;).&lt;/p&gt;

&lt;p id="p-2"&gt;No such problem over at &lt;a href="http://radiac.net/"&gt;radiac.net&lt;/a&gt;, where  Richard has outdone himself.&lt;/p&gt;
    
        &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/24-ways"&gt;24-ways&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/drew-mclellan"&gt;drew-mclellan&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/radiac"&gt;radiac&lt;/a&gt;&lt;/p&gt;
    

</summary><category term="24-ways"/><category term="drew-mclellan"/><category term="radiac"/></entry></feed>