Re:What's up Python? Django get background tasks, a new REPL...
by nomilk on Tuesday June 25, 2024 @10:34AM
(#40789169)
Blown away this is possible. When I was starting to learn to code and was overwhelmed when learning all the bits and pieces of rails, I wondered if everything necessary to run a very small app could be placed in a single file. I guess this is the answer, but in python/django instead of ruby/rails. It would be a fun exercise in ruby/rails too (not totally sure if it's possible, but suspect it may be, albeit probably resulting in a larger file than the one you give above!)
[ Parent
| on HN ]
Re:What's up Python? Django get background tasks, a new REPL...
by cassiogo on Tuesday June 25, 2024 @01:15PM
(#40791011)
Not that I think this is pratical or even looks good, but its also doable with rails
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.
Re:What's up Python? Django get background tasks, a new REPL...
by mg on Tuesday June 25, 2024 @01:35PM
(#40791208)
Is the db mandatory in Rails or could the db specific lines be removed from the code if no db is needed?
Re:What's up Python? Django get background tasks, a new REPL...
by cassiogo on Tuesday June 25, 2024 @01:43PM
(#40791307)
Not mandatory, you could remove that
Re:What's up Python? Django get background tasks, a new REPL...
by mg on Tuesday June 25, 2024 @01:56PM
(#40791478)
Cool. What would be the steps from a fresh Debian to get it running and see it in action?
Re:What's up Python? Django get background tasks, a new REPL...
by cassiogo on Wednesday June 26, 2024 @10:02AM
(#40800189)
Not sure debian has (a modern) ruby installed by default, but I think you only need to have a working ruby installation and running the script. On a sidenote, this came out recently and could interest you https://dashbit.co/blog/announcing-phoenix-playground
Re:What's up Python? Django get background tasks, a new REPL...
by mg on Wednesday June 26, 2024 @04:13PM
(#40804136)
I tried it like this:
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
^^^^^^^^
Re:What's up Python? Django get background tasks, a new REPL...
by ranger_danger on Wednesday June 26, 2024 @01:18AM
(#40796646)
This is also easily done by design with flask or quart, and probably several other frameworks.