我想擴展Django管理員登錄。大多數資源指向登錄後擴展視圖。擴展Django的管理員登錄(用戶名,密碼,網站)
我想站點添加到登錄的標準。
所以不是
- 用戶名
- 密碼
這將是
- 用戶名
- 密碼
- 網站
這樣本網站會檢查用戶是否屬於本網站的管理員,如果是,它只會加載屬於本網站的數據。
感謝
乾杯, 米奇
我想擴展Django管理員登錄。大多數資源指向登錄後擴展視圖。擴展Django的管理員登錄(用戶名,密碼,網站)
我想站點添加到登錄的標準。
所以不是
這將是
這樣本網站會檢查用戶是否屬於本網站的管理員,如果是,它只會加載屬於本網站的數據。
感謝
乾杯, 米奇
我不知道,因爲我在Django是newbee。
我會複製我的文件夾profject從原來的Django代碼管理代碼。然後,我會根據需要更改它,並將其放入已安裝的應用程序中。
我希望我能幫助你。正如我所說,我是django的新手。
Craphunter
您使用user profiles這一點。
這裏有一個基本的例子(這個代碼將走在應用的models.py
):
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
# Define a signal handler to be called after saving
# a User object
def user_save_handler(sender, **kwargs):
# If the save was creating a new user as opposed
# to updating an existing one, then create a
# UserProfile object and associate it with the User
if kwargs['created']:
# kwargs['instance'] is the User object we just
# created
UserProfile(user=kwargs['instance']).save()
# Hook the signal handler up to the User model's post_save
# signal
post_save.connect(user_save_handler, sender=User)
# Define your UserProfile class as usual.
class UserProfile(models.Model):
# user is a one-to-one reference to the associated
# User object. You need this field
user = models.OneToOneField(User)
# Now define any other fields you care about
birthday = models.DateField()