无法将数据从管理面板添加到 Django 中的网页
Unable to add data from admin panel to webpage in django
我试图将数据从管理员动态添加到我在 django 中的 HTML 页面,但是当我尝试在管理面板中添加数据时,它没有在 HTML 文件中显示任何内容。当我这样做时 makemigrations
我在下面得到这个
You are trying to add a non-nullable field 'link' to researchpaper without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option:
在管理面板中我收到这个错误
models.py
from django.db import models
class researchpaper(models.Model):
title = models.CharField(max_length=300)
publication = models.CharField(max_length=200)
link = models.CharField(max_length=300)
authors = models.CharField(max_length=200)
year = models.DateField("date published")
views.py
def publications(request):
data = researchpaper.objects.all()
return render(request, 'lab/publications.html',context={
"datas": data
})
urls.py
path('publications', views.publications, name='publications'),
HTML 文件
{% for public in datas %}
<tr>
<td>
<h5>2021</h5>
<p style="color: black;"><b>{{public.title}}</b></p>
<p style="font-size: 14px;"><i>{{public.publications}}</i></p>
<p style="font-size: 14px;"><i>{{public.author}}</i></p>
</td>
<td><a href="#"
target="blank" style="color: dodgerblue;"><i class="ai ai-google-scholar-square ai-2x"
style="padding-right: 10px;"></i></a></td>
</tr>
<tr>
<td>
<hr>
</td>
</tr>
{% endfor %}
为什么我会遇到这个问题,请帮助
迁移快照
选择第一个选项,它会再次出现,再次选择它并添加虚拟数据,如“R”,如果这不起作用,请尝试删除除 __init__
文件之外的所有迁移文件,并删除 db.sqlite3
文件,如果你使用 SQLite。
我试图将数据从管理员动态添加到我在 django 中的 HTML 页面,但是当我尝试在管理面板中添加数据时,它没有在 HTML 文件中显示任何内容。当我这样做时 makemigrations
我在下面得到这个
You are trying to add a non-nullable field 'link' to researchpaper without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Select an option:
在管理面板中我收到这个错误
models.py
from django.db import models
class researchpaper(models.Model):
title = models.CharField(max_length=300)
publication = models.CharField(max_length=200)
link = models.CharField(max_length=300)
authors = models.CharField(max_length=200)
year = models.DateField("date published")
views.py
def publications(request):
data = researchpaper.objects.all()
return render(request, 'lab/publications.html',context={
"datas": data
})
urls.py
path('publications', views.publications, name='publications'),
HTML 文件
{% for public in datas %}
<tr>
<td>
<h5>2021</h5>
<p style="color: black;"><b>{{public.title}}</b></p>
<p style="font-size: 14px;"><i>{{public.publications}}</i></p>
<p style="font-size: 14px;"><i>{{public.author}}</i></p>
</td>
<td><a href="#"
target="blank" style="color: dodgerblue;"><i class="ai ai-google-scholar-square ai-2x"
style="padding-right: 10px;"></i></a></td>
</tr>
<tr>
<td>
<hr>
</td>
</tr>
{% endfor %}
为什么我会遇到这个问题,请帮助
迁移快照
选择第一个选项,它会再次出现,再次选择它并添加虚拟数据,如“R”,如果这不起作用,请尝试删除除 __init__
文件之外的所有迁移文件,并删除 db.sqlite3
文件,如果你使用 SQLite。