python - 'WSGIRequest' object has no attribute 'Email' -


update3

i solved adding more code below after read tutorial once again , got error 'wsgirequest' object has no attribute 'email' after press button

the link not have querystring after press save button

def post_new(request):      #post = get_object_or_404(post)      #form = postform()      #return render_to_response(request, 'registration.html', {'pk': 12})      #return render(request, 'registration.html', {'form': form})     if request.method == "post":         form = postform(request.post)         if form.is_valid():             post = form.save(commit=false)              #post.author = request.user              post.email = request.email              post.projectname = request.projectname              post.username = request.username              post.company = request.company              post.contact = request.contact              post.initialpassword = request.initialpassword              post.usertype = request.usertype              post.businesstype = request.businesstype              post.published_date = timezone.now()              post.publish()             #self.published_date = timezone.now()             return redirect('post_detail', pk=post.pk)             #isexist = os.path.isfile('newusers.csv')               #with open('/home/martin/downloads/site1/site1/reg/newusers.csv', 'a') csvfile:               #fieldnames = ['name','email address','project','initial password','usertype','contact','businesstype','company']               #writer = csv.dictwriter(csvfile, fieldnames=fieldnames)               #if isexist == 0:                #writer.writeheader()               #writer.writerow({'name': request.user, 'email address': request.email, 'project': request.projectname, 'initial password': request.initialpassword,'usertype': request.usertype, 'contact': request.contact, 'businesstype': request.businesstype, 'company': request.company,})                return redirect('hello.html', pk=post.pk)     else:         form = postform()     return render(request, 'registration.html', {'form': form}) 

update2

after trying many methods, still have error, please download https://drive.google.com/file/d/0bxs_ao6uubdudhfqalfmqmy3u2c/view?usp=sharing

update1

<form method={% url 'post_detail' %}" method="post"" class="post-form">{% csrf_token %} 

after above update, still not run post_detail

only have

[25/may/2016 04:07:39] "get /reg/?csrfmiddlewaretoken=uwmaoreqgevfvdvdjkmsnwapxvijydna&email=a&projectname=a&username=a&company=a&contact=a&initialpassword=234&usertype=cyberport+tenant&businesstype=building http/1.1" 200 2276 

it not go hello.html, guess has not run post_detail not understand why pass when url use function name

def post_detail(request, pk):      post = get_object_or_404(post, pk=pk)      if request.method == "post":          form = postform(request.post, instance=post)          if form.is_valid():              post = form.save(commit=false)              post.author = request.user             post.email = request.email              post.projectname = request.projectname              post.username = request.username              post.company = request.company              post.contact = request.contact              post.initialpassword = request.initialpassword              post.usertype = request.usertype              post.businesstype = request.businesstype              post.published_date = timezone.now()              self.published_date = timezone.now()              #isexist = os.path.isfile('newusers.csv')               #with open('/home/martin/downloads/site1/site1/reg/newusers.csv', 'a') csvfile:               #fieldnames = ['name','email address','project','initial password','usertype','contact','businesstype','company']              #writer = csv.dictwriter(csvfile, fieldnames=fieldnames)              #if isexist == false:               #writer.writeheader()              #writer.writerow({'name': request.user, 'email address': request.email, 'project': request.projectname, 'initial password': request.initialpassword,'usertype': request.usertype, 'contact': request.contact, 'businesstype': request.businesstype, 'company': request.company,})               return redirect('hello.html', pk=post.pk)      else:     render(request, 'hello.html', {'form': form})          #form = postform(instance=post)        return render(request, 'hello.html', {'form': form}) 

i follow django girl web , feeling difficult, expect go /reg fill form , press save button go web /reg/<a number>

just expect trigger function after press save button

it has error

reverse 'reg/{{post.pk}}/' arguments '()' , keyword arguments '{}' not found. 0 pattern(s) tried: []

and try primary key pk , got error too

/home/martin/downloads/site1/site1/reg/models.py:37: removedindjango19warning: model class site1.reg.models.post doesn't declare explicit app_label , either isn't in application in installed_apps or else imported before application loaded. no longer supported in django 1.9. class post(models.model):

i had added site1.reg.models.post middleware_classes still have error

installed_apps = (     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',     'django.contrib.sites', )  middleware_classes = (     'django.contrib.sessions.middleware.sessionmiddleware',     'django.middleware.common.commonmiddleware',     'django.middleware.csrf.csrfviewmiddleware',     'django.contrib.auth.middleware.authenticationmiddleware',     'django.contrib.auth.middleware.sessionauthenticationmiddleware',     'django.contrib.messages.middleware.messagemiddleware',     'django.middleware.clickjacking.xframeoptionsmiddleware',     'django.middleware.security.securitymiddleware',     'site1.reg.models.post', )  registration.html  {% block content %}      <h1>new user registration</h1>      <form method="post" class="post-form">{% csrf_token %}          {{ form.as_p }}          <button type="submit" class="save btn btn-default" >save</button>      </form>  {% endblock %}  urls.py  django.conf.urls import include, url  . import views    urlpatterns = [      url(r'^reg/$', views.post_new, name='post_new'),      url(r'^reg/(?p<pk>\d+)/$', views.post_detail, name='post_detail'),  ]  views.py  .forms import postform  django.shortcuts import render  django.template.loader import get_template    def post_new(request):      form = postform()      return render(request, 'registration.html', {'form': form})    def post_detail(request, pk):      post = get_object_or_404(post, pk=pk)      if request.method == "post":          form = postform(request.post, instance=post)          if form.is_valid():              post = form.save(commit=false)              post.author = request.user              post.projectname = request.projectname              post.username = request.username              post.company = request.company              post.contact = request.contact              post.initialpassword = request.initialpassword              post.usertype = request.usertype              post.businesstype = request.businesstype              post.published_date = timezone.now()              post.save()              return redirect('registration.html', pk=post.pk)      else:          form = postform(instance=post)       return render(request, 'registration.html', {'form': form})  models.py  django.db import models  django.utils import timezone django.apps import appconfig  import csv import os.path  usertype = (       ('cyberport tenant', 'cyberport tenant'),     ('smartspace user', 'smartspace user'),     ('cyberport incubate', 'cyberport incubate'),     ('collaboration center subscriber', 'collaboration center subscriber'),     ('cyberport alumnus', 'cyberport alumnus'),     ('technology partner', 'technology partner'),     ('hkosug', 'hkosug'),     ('others', 'others'), )   businesstype = (       ('building', 'building'),     ('data analysis', 'data analysis'),     ('digital entertainment', 'digital entertainment'),     ('education', 'education'),     ('games', 'games'),     ('gaming', 'gaming'),     ('ict', 'ict'),     ('marketing', 'marketing'),     ('social media', 'social media'),     ('others', 'others'), )   class myappconfig(appconfig):     name = 'src.my_app_label'      def ready(self):         post_migrate.connect(do_stuff, sender=self)   class post(models.model):      author = models.foreignkey('auth.user')      email = models.charfield(max_length=70)     projectname = models.charfield(max_length=70)     username = models.charfield(max_length=70)     company = models.charfield(max_length=70)     contact = models.charfield(max_length=70)     initialpassword = models.charfield(max_length=70)     usertype = models.charfield(max_length=30, choices=usertype)     businesstype = models.charfield(max_length=30, choices=businesstype)     #usertype = models.choicefield(choices=usertype, required=true )     #businesstype = models.choicefield(choices=businesstype, required=true )      #projectname = models.textfield()      created_date = models.datetimefield(default=timezone.now)      published_date = models.datetimefield(blank=true, null=true)        def publish(self):          self.published_date = timezone.now()         isexist = os.path.isfile('newusers.csv')          open('/home/martin/downloads/site1/site1/reg/newusers.csv', 'a') csvfile:           fieldnames = ['name','email address','project','initial password','usertype','contact','businesstype','company']           writer = csv.dictwriter(csvfile, fieldnames=fieldnames)           if isexist == false:              writer.writeheader()           writer.writerow({'name': username, 'email address': email, 'project': projectname, 'initial password': initialpassword,'usertype': usertype, 'contact': contact, 'businesstype': businesstype, 'company': company,})           self.save()        def __str__(self):          return self.title  forms.py  django import forms    .models import post   usertype = (       ('cyberport tenant', 'cyberport tenant'),     ('smartspace user', 'smartspace user'),     ('cyberport incubate', 'cyberport incubate'),     ('collaboration center subscriber', 'collaboration center subscriber'),     ('cyberport alumnus', 'cyberport alumnus'),     ('technology partner', 'technology partner'),     ('hkosug', 'hkosug'),     ('others', 'others'), )   businesstype = (       ('building', 'building'),     ('data analysis', 'data analysis'),     ('digital entertainment', 'digital entertainment'),     ('education', 'education'),     ('games', 'games'),     ('gaming', 'gaming'),     ('ict', 'ict'),     ('marketing', 'marketing'),     ('social media', 'social media'),     ('others', 'others'), )    class postform(forms.modelform):        #if form.is_valid():       #post = form.save(commit=false)       #post.author = request.user       #post.published_date = timezone.now()       #post.save()m      class meta:          model = post          fields = ('email', 'projectname', 'username', 'company', 'contact', 'initialpassword','usertype','businesstype')     #fields = ('title', 'text',)         usertype = forms.choicefield(choices=usertype, required=true )         businesstype = forms.choicefield(choices=businesstype, required=true ) 

this not valid syntax:

<form method={% url 'post_detail' %}" method="post"" class="post-form"> 

the url want post form should in action attribute:

<form action="{% url 'post_detail' %}" method="post"" class="post-form"> 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -