Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Request Method: GET
- 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
- from django.db import models
- from 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])
- from django import forms
- from userprofile.models import UserProfile
- class UserProfileForm (forms.ModelForm):
- class Meta:
- user = UserProfile
- fields = ('likes_cheese', 'favorite_hamster_name')
- from django.shortcuts import render_to_response
- from django.http import HttpResponse, HttpResponseRedirect, Http404
- from django.template import loader, RequestContext
- # from django.core.context_processors import csrf
- from userprofile.forms import UserProfileForm
- from 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)
- class UserProfileForm (forms.ModelForm):
- class Meta:
- user = UserProfile
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement