How to display scraping data in Django admin panel
Simply go to the app each in the same directory as models.py file and then you should find admin.py and if not just create display scraping data in Django admin panel. scraping data means another site to get data and its data display your site.
This tutorial is how to display Django scraping data in the admin panel. first, create table in model file and then display data used to the admin.py file.
Also read : How to create crawl a web page with scrapy and python
1) models.py
from django.db import models
class BlogPost(models.Model):
name = models.TextField(null=True)
image = models.TextField(null=True)
category = models.TextField(null=True)
created_at = models.DateTimeField(auto_now_add=True,null=True)
class Meta:
db_table = 'posts'
2) apply migrations
$ python manage.py makemigrations
$ python manage.py migrate
3) admin.py
from django.contrib import admin
from django.contrib.auth.models import Group
from django.utils.html import format_html
from .models import BlogPost
admin.site.unregister(Group)
admin.site.site_header = "Devnote Scrapy"
class listAllPost(admin.ModelAdmin):
list_display = ('name','image_html','category')
list_filter = ('created_at',)
search_fields = ('name','category',)
def image_html(self,obj):
return format_html('<img src="%s" width="100px">' % (obj.image))
image_html.allow_tags = True
admin.site.register(BlogPost,listAllPost)
Check you admin again and you will find the saved data displayed.
Not working
Not working it is showing the problem in the for loop
Pls
Give Solution
Please send a screenshot. what is getting the error?