python - ModelForm has no model class specified -
please solve problem .
i tried create user profile page , user reaches after registration , login. after loading address / userprofile / loaded view user_profile (request).
startup page displays following error message :
request method: request url: http://127.0.0.1:8000/userprofile/ django version: 1.6.2 exception type: valueerror exception value: modelform has no model class specified. exception location: c: \ python33 \ lib \ site-packages \ django \ forms \ models.py in __ init__, line 308
models.py:
from django.db import models django.contrib.auth.models import user class userprofile (models.model): user = models.onetoonefield (user) likes_cheese = models.booleanfield (default = true) favorite_hamster_name = models.charfield (max_length = 50) user.profile = property (lambda u: userprofile.objects.get_or_create (user = u) [ 0])
forms.py:
from django import forms userprofile.models import userprofile class userprofileform (forms.modelform): class meta: user = userprofile fields = ('likes_cheese', 'favorite_hamster_name')
views.py:
from django.shortcuts import render_to_response django.http import httpresponse, httpresponseredirect, http404 django.template import loader, requestcontext # django.core.context_processors import csrf userprofile.forms import userprofileform django.contrib.auth.decorators import login_required @ login_required def user_profile (request): if request.method == 'post': form = userprofileform (request.post, instance = request.user.profile) if form.is_valid (): form.save () return httpresponseredirect ('/ accounts / loggedin /') else: user = request.user profile = user.profile form = userprofileform (instance = profile) args = {} # args.update (csrf (request)) args ['form'] = form return render_to_response ('profile.html', args)
when create user profile page , used following tutorials
class userprofileform (forms.modelform): class meta: user = userprofile ...
you mean model = userprofile
, not user = userprofile
.
Comments
Post a Comment