Thursday, May 26, 2016

Re: Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

so far, the link do not have querystring, the error is WSGIRequest' object has no attribute 'Email'

On Thursday, May 26, 2016 at 10:24:44 PM UTC+8, ludovic coues wrote:
Have you done the django tutorial ? It help a lot when starting with django.

Your problem come from site1/urls.py . `include(admin.site.urls)` work
because you import admin. `include(site1.reg.urls)` cannot work
because site1 is not defined.

Also, the djangogirls tutorial [1] have a great chapter about form.

[1] http://tutorial.djangogirls.org/en/django_forms/

2016-05-26 3:46 GMT+02:00 meInvent bbird <jobma...@gmail.com>:
> https://drive.google.com/file/d/0Bxs_ao6uuBDUQm5jOEdCOFowa0U/view?usp=sharing
>
> On Tuesday, May 24, 2016 at 9:07:25 PM UTC+8, ludovic coues wrote:
>>
>> It should work better this way:
>> <button type="submit" class="save btn btn-default"
>> onClick="window.location.href='{% url 'post_detail' pk=post.pk
>> %}'">Save</button>
>>
>> the url template tag take a route name, not an url as it first argument.
>>
>> 2016-05-24 10:19 GMT+02:00 meInvent bbird <jobma...@gmail.com>:
>> > Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments
>> > '{}' not found. 0 pattern(s) tried: []
>> >
>> > i follow django girl web , expect to go to /reg to fill a form and press
>> > save button then go to web /reg/<a number>
>> >
>> > it has 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"
>> > onClick="window.location.href='{% url 'reg/{{post.pk}}/'
>> > %}'">Save</button>
>> >
>> >     </form>
>> >
>> > {% endblock %}
>> >
>> > urls.py
>> >
>> > from django.conf.urls import include, url
>> >
>> > from . 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
>> >
>> > from .forms import PostForm
>> >
>> > from django.shortcuts import render
>> >
>> > from 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
>> >
>> > from django.db import models
>> >
>> > from django.utils import timezone
>> > from 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')
>> >         with open('/home/martin/Downloads/site1/site1/reg/newusers.csv',
>> > 'a') as 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
>> >
>> > from django import forms
>> >
>> >
>> >
>> > from .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
>> > )
>> >
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to django-users...@googlegroups.com.
>> > To post to this group, send email to django...@googlegroups.com.
>> > Visit this group at https://groups.google.com/group/django-users.
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/django-users/4c6f022c-9222-4991-b6f7-9574b9386c16%40googlegroups.com.
>> >
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c1208d34-7a9c-41cc-b42b-e2021b6c168f%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/85562895-3302-4ca0-8751-9ad5842684d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment