AUTH_USER_MODEL
त्रुटि EDIT3 में हल करने में सक्षम नहीं है। पासवर्ड अभी भी फॉर्म के माध्यम से उपयोगकर्ता निर्माण पर सहेज नहीं पाएंगे।AUTH_USER_MODEL मॉडल को संदर्भित करता है .. जिसे स्थापित नहीं किया गया है और बनाया गया है AbstractUser मॉडल
मैं Django 1.5 का उपयोग नए उपयोगकर्ता ओवरराइड/एक्सटेंशन सुविधाओं के साथ खेल रहा हूं, और मैं अपने पंजीकरण फॉर्म के माध्यम से नए उपयोगकर्ताओं को पंजीकृत करने में सक्षम नहीं हूं - केवल व्यवस्थापक के माध्यम से।
Manager isn't available; User has been swapped for 'poker.PokerUser'
models.py:
class PokerUser(AbstractUser):
poker_relate = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
token = models.EmailField()
USER_CHOICES = (
('1', 'Staker'),
('2', 'Horse')
)
user_type = models.CharField(choices=USER_CHOICES, max_length=10)
username1 = models.CharField(null=True, blank=True, max_length=40)
username2 = models.CharField(null=True, blank=True, max_length=40)
username3 = models.CharField(null=True, blank=True, max_length=40)
username4 = models.CharField(null=True, blank=True, max_length=40)
username5 = models.CharField(null=True, blank=True, max_length=40)
PokerUserForm
मॉडल:
class PokerUserForm(UserCreationForm):
class Meta:
model = PokerUser
fields = ('username','password1','password2','email','user_type','token','username1','username2','username3','username4','username5',)
मैं का प्रयास किया है बदलने के लिए जब पंजीकरण फार्म के माध्यम से दर्ज की, मैं निम्नलिखित त्रुटि मिलती है मॉडल में का उपयोग करने के लिए मॉडल को स्पष्ट रूप सेसेट करके मॉडल को परिभाषित करने के बजायबजाय model = PokerUser
लेकिन फिर मैं निम्न त्रुटि प्राप्त:
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'poker.PokerUser' that has not been installed
मेरे AUTH_USER_MODEL
में सेटअप है मेरी settings.py
तो जैसे:
AUTH_USER_MODEL = 'poker.PokerUser'
पर हम चले - views.py
में मेरी पंजीकरण दृश्य:
def UserRegistration(request):
player = PokerUser()
if request.method == 'POST':
form = PokerUserForm(request.POST, instance=player)
if form.is_valid():
player.email_address = form.cleaned_data['email']
player.user_type = form.cleaned_data['user_type']
# if player is staker, token is their own email. otherwise their token is their staker's email and
# their relation is their staker
if player.user_type == '1' or player.user_type == 'staker':
player.token = player.email_address
else:
player.token = form.cleaned_data['token']
staker = PokerUser.objects.get(email=player.token)
player.poker_relate = staker
player.save()
return HttpResponseRedirect('/')
else:
form = PokerUserForm()
initialData = {'form': form}
csrfContext = RequestContext(request, initialData)
return render_to_response('registration/register.html', csrfContext)
EDIT1:
According to the docs, UserCreationForm
कस्टम उपयोगकर्ता कक्षाओं के उपयोग के लिए पुनर्निर्मित किया जाना चाहिए।
इस प्रकार मैं पूरी UserCreationForm
overrode:
class UserCreationForm(forms.ModelForm):
"""
A form that creates a user, with no privileges, from the given username and
password.
"""
error_messages = {
'duplicate_username': _("A user with that username already exists."),
'password_mismatch': _("The two password fields didn't match."),
}
username = forms.RegexField(label=_("Username"), max_length=30,
regex=r'^[\[email protected]+-]+$',
help_text=_("Required. 30 characters or fewer. Letters, digits and "
"@/./+/-/_ only."),
error_messages={
'invalid': _("This value may contain only letters, numbers and "
"@/./+/-/_ characters.")})
password1 = forms.CharField(label=_("Password"),
widget=forms.PasswordInput)
password2 = forms.CharField(label=_("Password confirmation"),
widget=forms.PasswordInput,
help_text=_("Enter the same password as above, for verification."))
class Meta:
model = PokerUser
fields = ('username','password1','password2','email','user_type','token','username1','username2','username3','username4','username5',)
def clean_username(self):
# Since User.username is unique, this check is redundant,
# but it sets a nicer error message than the ORM. See #13147.
username = self.cleaned_data["username"]
try:
PokerUser.objects.get(username=username)
except PokerUser.DoesNotExist:
return username
raise forms.ValidationError(self.error_messages['duplicate_username'])
def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError(
self.error_messages['password_mismatch'])
return password2
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
और यह इस त्रुटि को हल करने में सक्षम था:
The Manager isn't available; User has been swapped for 'poker.PokerUser'
अब, उपयोगकर्ताओं को बनाया है, लेकिन में लॉग इन करने में सक्षम नहीं हैं मिलता है जब मैं व्यवस्थापक में उपयोगकर्ताओं की जांच करता हूं, तो पासवर्ड के अलावा सभी जानकारी सही होती है। व्यवस्थापक में मैन्युअल रूप से पासवर्ड जोड़ना सही ढंग से काम नहीं कर रहा है। फिर भी, व्यवस्थापक के माध्यम से उपयोगकर्ताओं को सही ढंग से जोड़ना।
संपादित करें 2:
मैं अभी भी पंजीकरण फार्म के माध्यम से बनाया मेरी AbstractUser से कोई भी मॉडल के रूप में प्रवेश करने में असमर्थ हूँ।मैं पूरी तरह से UserCreationForm
अधिरोहित है जैसा कि ऊपर उल्लिखित है, और इस त्रुटि के साथ get_user_model()
को लागू करने में असमर्थ हूँ:
AUTH_USER_MODEL refers to model 'poker.PokerUser' that has not been installed
get_user_model()
के लिए Django कोड है:
def get_user_model():
"Return the User model that is active in this project"
from django.conf import settings
from django.db.models import get_model
try:
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
except ValueError:
raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
user_model = get_model(app_label, model_name)
if user_model is None:
raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL)
return user_model
जब से मैं में AUTH_USER_MODEL = 'poker.PokerUser'
सेटअप मेरा settings.py
, यह काम करना चाहिए। मैंने Django कंसोल के माध्यम से इसे सत्यापित कर लिया है:
>>> from django.contrib.auth import get_user_model
>>> settings.AUTH_USER_MODEL
Out[14]: 'poker.PokerUser'
>>> from django.db.models import get_model
>>> app_label, model_name = settings.AUTH_USER_MODEL.split('.')
>>> user_model = get_model(app_label, model_name)
>>> user_model
Out[18]: poker.models.PokerUser
हालांकि कार्यान्वयन अभी भी सही तरीके से काम नहीं करता है।
यदि आपने इसे अभी तक पढ़ा है, धन्यवाद!
EDIT3:
AUTH_USER_MODEL refers to model 'poker.PokerUser' that has not been installed
तय किया गया है। मुझे गलती से UserCreationForm
था कि मैंने के बजाय poker.models
में फिर से बनाया, इसलिए जब मैं get_user_model()
चला गया जो poker.PokerUser
को सौंपा गया था, तो यह हल नहीं हो सका क्योंकि यह पहले से ही उस स्थान पर था।
अब एकमात्र मुद्दा यह है कि नए उपयोगकर्ताओं को बनाते समय, उनके पासवर्ड सहेजे नहीं जाएंगे। मैं प्रिंट बयान यहाँ रखकर UserCreationForm
में एक भी विधि करने के लिए नीचे यह संकुचित है:
def clean_password2(self):
password1 = self.cleaned_data.get("password1")
print password1
password2 = self.cleaned_data.get("password2")
print password2
if password1 and password2 and password1 != password2:
raise forms.ValidationError(
self.error_messages['password_mismatch'])
print password2
return password2
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data["password1"])
print self.cleaned_data["password1"]
if commit:
user.save()
return user
clean_password2
प्रदर्शन सादा पाठ पासवर्ड में print password1
और print password1
बयान, लेकिन save
विधि में print self.cleaned_data["password1"]
खाली है। मेरा फॉर्म डेटा सहेजने के तरीके को क्यों नहीं भेजा जा रहा है?
टीएल; डीआरAbstractUser
मॉडल निर्माण दोनों व्यवस्थापक और पंजीकरण फॉर्म के माध्यम से काम कर रहा है, लेकिन केवल व्यवस्थापक के माध्यम से बनाए गए उपयोगकर्ता लॉगिन करने में सक्षम हैं। पंजीकरण फॉर्म के माध्यम से बनाए गए उपयोगकर्ता लॉग इन करने में असमर्थ हैं और पासवर्ड के बिना सहेजे जाने लगते हैं - अन्य सभी जानकारी सही ढंग से सहेजी जाती है।
आप डॉक्स विशेष रूप से व्यवस्थापक से संबंधित संदर्भित कर रहे हैं हल। मुद्दा व्यवस्थापक के साथ नहीं है। व्यवस्थापक में उपयोगकर्ताओं को बनाना सही ढंग से काम करता है। मुद्दा व्यवस्थापक के बाहर उपयोगकर्ताओं को बना रहा है। –
सवाल यह है: क्या व्यवस्थापक के साथ बनाए गए सही प्रकार के उपयोगकर्ता हैं? क्या आपने अपने नए मॉडल का उपयोग करने के लिए व्यवस्थापक को कॉन्फ़िगर किया है? – stefanw
जबकि मैं निश्चित रूप से आपके समय और उत्तरों की सराहना करता हूं, मैंने अपनी मूल पोस्ट में इन सभी चिंताओं को दूर करने के लिए काफी प्रयास किए हैं। कृपया अंतिम अनुच्छेद देखें - "अब, उपयोगकर्ता बनाए गए हैं लेकिन लॉग इन करने में सक्षम नहीं हैं। जब मैं व्यवस्थापक में उपयोगकर्ताओं की जांच करता हूं, तो सभी जानकारी पासवर्ड को छोड़कर सही होती है। व्यवस्थापक में मैन्युअल रूप से पासवर्ड जोड़ना सही ढंग से काम नहीं कर रहा है। फिर भी, व्यवस्थापक के माध्यम से उपयोगकर्ताओं को सही तरीके से जोड़ना। " व्यवस्थापक में बनाया गया उपयोगकर्ता सही ढंग से काम करते हैं। 'UserCreationForm' उपयोगकर्ताओं को ओवरराइड करने के बाद अब व्यवस्थापक के बाहर बनाते हैं, लेकिन सही नहीं हैं। –