作为一个对 Django 比较熟的人,稍微学习过 Rails,感觉大部分和 Django 差不多?对于一般性的认知提升来说,有深入学 Rails 的价值吗?
我没有用过 Django,单从文档看,Django 对前端技术不持立场,开发者根据自己的情况选择前端技术;而 Rails 创始人 DHH 强烈推荐全栈开发,默认包括一个叫 hotwire 的从网页到移动端的前端框架,当然如果不想用 hotwire 也可以选择集成其他“主流”的前端技术。
Rails 7.1 发布 Hacker News 上有一些多框架使用者的评论,可以看一下 https://news.ycombinator.com/item?id=37787130
写过好多年 Rails 的说,最近也在用 Django 写业务,觉得比较舒服的地方是 Django Admin, 简单的后台管理功能,很方便 其他的没有 Rails 香,比如 ORM
I am using Django. Let me tell you how ugly Django template is: https://docs.djangoproject.com/en/4.2/topics/templates/
For example.
{% extends 'layout_basic_table.html' %}
{% block title %}Need Further Translation Texts{% endblock title %}
{% block header_title %}Need Further Translation Texts{% endblock header_title %}
{% block table_content %}
<thead>
<tr>
<th>#</th>
{% for field in fields %}
<th>{{ field }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for item in need_translation_texts %}
<tr>
<td>{{ forloop.counter }}</td>
<td>
<a href="https://api.pagg-prod.com/admin/api/translationdictionary/{{ item.0 }}/change/">
{{ item.0 }}
</a>
</td>
<td>{{ item.1 }}</td>
</tr>
{% endfor %}
</tbody>
{% endblock table_content %}
template
!Template in Django is just for display.
You can never write any Python code in template
!
That means if you want to make the item.1
to be lower-cased, no direct way in template to do it.
You have to prepare the item.1
well in the backend controller code.
So for Ruby developer, you are probably want to write code in views like "#{school.name} #{school.ranking}"
.
This is not allowed in Django template. You have to do it in the Django views.py
(like: Ruby controller), and create variables like school_name
, school_ranking
and use them directly in template.
So Django is awful. Web companies using Django are on the edge of bankrupt.
Hello Mark. I am afraid what you said was wrong. Here: code for nested iteration is an example that ERB works well enough in Sinatra. Please describe clearly if I misunderstand you. I am satisfied with ERB.