我很苦惱。我創建了一個應用程序,管理員創建用戶,並將詳細信息發送到註冊的電子郵件。但是現在我的客戶希望由admin創建的用戶保存在firebase中。我從來沒有進入firebase,也做過研究,但找不到可以解決我的問題的任何資源。使用django註冊用戶數據到firebase
代碼之前是
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.conf import settings
from django.db.models.signals import post_save
from django.core.mail import EmailMessage
from django.utils import timezone
from django.dispatch import receiver
from django.db import models
class UserProfile(models.Model):
user = models.ForeignKey(User,null=True)
first_name = models.CharField(max_length=100,blank=True,null=True,help_text=("enter the first name of user"))
last_name = models.CharField(max_length=100,blank=True,null=True,help_text=("enter the last name"))
address = models.CharField(max_length=300,blank=True,null=True,help_text=("enter the address"))
contact = models.CharField(max_length=100,blank=True,null=True,help_text=("enter the contact"))
email = models.EmailField(max_length=100,blank=True,null=True,help_text=("enter the email"))
username = models.CharField(max_length=100,blank=True,null=True,help_text=("enter the username"))
password = models.CharField(max_length=100,blank=True,null=True,help_text=("enter the strong password"))
creation_date = models.DateTimeField(editable=False,null=True)
last_modified = models.DateTimeField(editable=False,null=True)
def save(self, *args, **kwargs):
if not self.creation_date:
self.creation_date = timezone.now()
self.last_modified = timezone.now()
return super(UserProfile, self).save(*args, **kwargs)
def __str__(self):
return (self.username)
@receiver(post_save,sender=UserProfile)
def send_user_data_when_created_by_admin(sender, instance, **kwargs):
first_name = instance.first_name
print('first name is',first_name)
last_name = instance.last_name
address = instance.address
print('address is',address)
contact = instance.contact
email = instance.email
username = instance.username
password = instance.password
html_content = "your first name:%s <br> last name:%s <br> address:%s <br> contact:%s <br> email:%s <br> username:%s <br> password:%s"
from_email = settings.DEFAULT_FROM_EMAIL
message=EmailMessage('welcome',html_content %(first_name,last_name,address,contact,email,username,password),from_email,[email])
message.content_subtype='html'
message.send()
我如何保存用戶數據火力每當管理員創建一個從管理面板的新用戶?
既然你已經有一個'post_save'信號處理程序,你可以簡單地添加所需的代碼出現。這裏解釋過於寬泛,但你可以使用[python-firebase](https://github.com/ozgur/python-firebase)。 – Selcuk
你能提供一個與此相關的鏈接嗎?我從來沒有使用過Firebase,我完全空白。 – pri