require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '~> 7.1'
gem "sqlite3", "~> 1.4"
end
require 'rails'
require 'active_record/railtie'
database = 'app_development.sqlite3'
ENV['DATABASE_URL'] = "sqlite3:#{database}"
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: database)
ActiveRecord::Schema.define do
create_table :my_table, force: true do |t|
t.integer :my_table_id
end
end
class App < Rails::Application
routes.append do
root to: 'home#index'
end
end
class HomeController < ActionController::Base
def index
render inline: 'HOME'
end
end
App.initialize!
run App
For very small apps on ruby land sinatra and roda are the right choices.
On python the choice would be flask instead of the single file django. 1: apt install ruby
2: Put your code in test.rb
3: ruby test.rb
I then I got: Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
\e[0m
current directory: /var/lib/gems/3.1.0/gems/stringio-3.1.1/ext/stringio
/usr/bin/ruby3.1 -I /usr/lib/ruby/vendor_ruby -r ./siteconf20240626-4044-iylnuy.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.
So I tried: 4: apt install ruby-dev
5: ruby test.rb
Then I got: [4147, #<Thread:0x00007f9a4af6bc60 run>, #<NameError: uninitialized constant Gem::Source
(defined?(@source) && @source) || Gem::Source::Installed.new
^^^^^^^^And not every application that uses a db needs an ORM.
You probably can build an ORM into the single file. But I'm not saying every application should be developed as a single file forever. I just like that you can start with one and expand later.
What makes django useful is the admin, auth, session and so on that are all built around the ORM.
from django.db import models
from django.db import connection
class MyModel(models.Model):
name = models.CharField(max_length=255)
class Meta:
app_label = 'myapp'
with connection.schema_editor() as schema_editor:
schema_editor.create_model(MyModel)
# from django.core.management import call_command
# call_command('makemigrations', 'myapp')
# call_command('migrate', 'myapp')do you really consider this a lean process in 2024?
WSGI is old tech that in your example requires extra packages and code in project to work. By now Python should stand on its own and handle this independently, being proxied to by better http servers like nginx or caddy.
No it's not. Please cite reputable sources.
Many share my opinion, and I don't have to prove that. Nor should I, and neither do you for any position you have. Address the argument.
CPython is fully commercialized.
And I'm certainly not unique amongst other pythonistas, this has been a goal for literal decades.
You can turn a fresh Debian machine into a running Django web app by just doing:
And then creating the one file Django needs:/var/www/mysite/mysite/wsgi.py:
And then telling Apache where to look for it:/etc/apache2/sites-enabled/000-default.conf:
And voilá, you have a running Django application, which you can expand upon to any size and complexity.If you want to try it in a docker container, you can run
perform the steps above and then access the Django application at 127.0.0.1