Python Django显示不同的型号/选项卡
我被卡住了。每次在django中显示另一个表时,我都会尝试在我的view.py代码中使用相同的def 第一个问题是我无法将在url中输入的字符串传输到模型。 例如,如果我键入0.0.0.0:8000/polls/Cashflows,我想显示数据库的表CashflowsPython Django显示不同的型号/选项卡,python,html,django,Python,Html,Django,我被卡住了。每次在django中显示另一个表时,我都会尝试在我的view.py代码中使用相同的def 第一个问题是我无法将在url中输入的字符串传输到模型。 例如,如果我键入0.0.0.0:8000/polls/Cashflows,我想显示数据库的表Cashflows from django.http import HttpResponse from django.template import loader from django.apps import apps from .models i
from django.http import HttpResponse
from django.template import loader
from django.apps import apps
from .models import Cashflows,Garbage,Inputacturial
def index(request):
list_cashflows=Cashflows.objects.all()
template=loader.get_template('polls/index.html')
context={'list_cashflows':list_cashflows,}
return HttpResponse(template.render(context,request))
def detail(request, table):
#model = apps.get_model('polls', 'table')
#model=apps.get_model ( 'polls',table.split('.',1))
model=Cashflows
liste_column=model.objects.all()
b=model._meta.get_fields()
#b=a[:]
liste_fields=list(b)
template=loader.get_template('polls/index2.html')
context={'liste_column':liste_column,'liste_fields':liste_fields,}
return HttpResponse(template.render(context,request))
我尝试了不同的选择,但没有一个真正适合我
我的下一个问题是显示这些不同的表。
我试着从字段名开始
<table>{% for item in liste_fields%}
<tr><th>liste_fields.item</th>
</tr>
{% endfor %}
</table>
{%用于列表字段%中的项]
liste_fields.item
{%endfor%}
它只是给我三行liste.fields.item,而不是每个字段的列。你能帮我吗 您已经使用了o方法
详细名称
例如:
list_fields=[field.verbose_现金流中字段的名称。_meta.get_fields()如果不是field.is_relation或field.one_to_one或(field.many_to_one和field.related_model)]
1。你的
url.py
看起来怎么样?2.您需要将变量名放在双大括号中,而不是在for循环中引用数组/列表名。所以只要{{item}}
.urlpatterns=[path('''views.index,name='index'),path('/',views.detail,name='detail'),]