Humm, maybe you should right, here is my views.py :

from django.template import Context, loader, RequestContext
from myApp.models import Article, Commentaire
from django.http import HttpResponse
from django.contrib import auth
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from django.contrib.sessions.models import Session
from django.shortcuts import get_object_or_404, render_to_response
from myApp.forms import CommentForms

and here the view which don t work :
def article(request, id):
article = Article.objects.get(id=id)
commentaires = Commentaire.objects.filter(video=video.id
).order_by("-dateComment")

c = Context({
'article' : article,
'commentaires' : commentaires,
})
 # preparation du formulaire de commentaire
if request.method == 'POST':
form = CommentForms(request.POST)
if form.is_valid(): #validation
cf_comment = form.cleaned_data['commentaire']
cf_writer = request.user
cf_date = datetime.datetime.now()
cf_article = request.article
#return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))
else :
form = CommentForms()


return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))

and finally my forms.py :

from django import forms
from django.contrib.auth.models import User
from myApp.models import Article

class CommentForms (forms.Form):
    cf_comment = forms.CharField()
    cf_writer = forms.User()
    cf_date = forms.DateField()
    cf_video = forms.Article()

This one don't work, i can't launch my webApp, when i hit it I have this
error :
ViewDoesNotExist at /

Tried index in module empire.myApp.views. Error was: 'module' object
has no attribute 'User'

Request Method:GETRequest URL:http://127.0.0.1:8000/Django Version:1.3Exception
Type:ViewDoesNotExistException Value:

Tried index in module app.myApp.views. Error was: 'module' object has
no attribute 'User'



Now i delete the object attribute of my form (ie : User and Article ) :
my forms.py :
from django import forms
from django.contrib.auth.models import User
from myApp.models import Article

class CommentForms (forms.Form):
    cf_comment = forms.CharField()
    #cf_writer = forms.User()
    cf_date = forms.DateField()
    #cf_video = forms.Video()

and my view (i keep the same import ) :
def article(request, id):
article = Article.objects.get(id=id)
commentaires = Commentaire.objects.filter(video=video.id
).order_by("-dateComment")

c = Context({
'article' : article,
'commentaires' : commentaires,
})
 # preparation du formulaire de commentaire
if request.method == 'POST':
form = CommentForms(request.POST)
if form.is_valid(): #validation
cf_comment = form.cleaned_data['commentaire']
#cf_writer = request.user
cf_date = datetime.datetime.now()
#cf_article = request.article
#return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))
                        print 'IF'

else :
form = CommentForms()
                        print 'ELSE'

The application launch fine but when i submit the form (obviously) i go in
the ELSE.

Any idea ?

Thx for your help :)


return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))



On Fri, Aug 12, 2011 at 3:16 PM, Daniel Roseman <dan...@roseman.org.uk>wrote:

> Your error has nothing to do with your form. There is an import problem in
> your empireFront.views module which is preventing it from being imported.
>
> Somewhere you are trying to import something called "User" from a place
> that doesn't have any such class. It would help if you posted the imports in
> that file.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/OeT67jgufvoJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to