我想为用户创建一个仪表板,以显示其SEO得分。 我的projet 3应用程序上有: -Account:使用基本的django的Usercreation表单的登录/注册表单。它具有字段(电子邮件,名字,姓氏) 分析:使用刮板扫描所有网站,并在数据库中保存seo得分,电子邮件以及是否可以联系的同意 我想做的是合并这两个表,也许使用前键或我不知道是什么。 为了什么?当我在django admin上单击用户时,我想要一张桌子,上面有他的名字,姓氏,电子邮件,seo得分和他的网站,并且他可以登录他的邮件。在此仪表板上,我将向他显示与他的网站有关的所有数据,这就是为什么我必须在登录平台和网站抓取器之间建立连接。
Settings.py的一部分:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'key'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dashboard',
'account',
'analyse',
]
models.py(分析抓取工具):
from django.db import models
class Detail(models.Model):
email = models.EmailField(max_length=100, blank=True, null=True)
website = models.URLField(max_length=250)
seo_score = models.IntegerField(default=0)
contacted = models.CharField(max_length=20, default="yes")
# pdf = models.FileField(upload_to='pdf/', default='settings.MEDIA_ROOT/pdf/sample.pdf')
def __str__(self):
return self.email
forms.py(account):它正在管理日志记录/注册:
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class Register(UserCreationForm):
username = forms.CharField(max_length=30, required=False)
first_name = forms.CharField(max_length=30, required=False)
last_name = forms.CharField(max_length=30, required=False)
email = forms.EmailField(max_length=254)
class Meta:
model = User
fields = ('username','first_name', 'last_name', 'email', 'password1', 'password2', )
views.py(帐户):
def register(request):
if request.method == 'POST':
form = Register(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
first_name = form.cleaned_data.get('first_name')
last_name = form.cleaned_data.get('last_name')
email = form.cleaned_data.get('email')
website = form.cleaned_data.get('website')
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=raw_password)
return redirect('/dashboard')
else:
form = Register()
return render(request, 'register.html', {'form': form})
所以在我的Django管理员中,我有2个表: 与我单击的用户一起,有名字姓氏电子邮件 另一个带有Détails的网站,我点击了seo得分等。当有人尝试通过存在刮板的主页扫描其网站时,数据即将到来。
请帮忙吗?