python - TypeError: post() missing 1 required positional argument: 'slug' -
i'm pretty new django, naturally hit wall. i'm getting error message, when trying create blog page. tried read on error i'm getting, no avail.
full error:
typeerror @ /blog/ post() missing 1 required positional argument: 'slug' request method: request url: http://127.0.0.1:8000/blog/ django version: 1.9.2 exception type: typeerror exception value: post() missing 1 required positional argument: 'slug' exception location: /usr/lib/python3.4/site-packages/django/core/handlers/base.py in get_response, line 147 python executable: /usr/bin/python3.4 python version: 3.4.3 python path: ['/home/rumen/desktop/venv2/blog_project', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/lib/python3.4/site-packages', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
below model:
from django.db import models django import forms django.core.urlresolvers import reverse class post(models.model): title = models.charfield(max_length=255) slug = models.slugfield(unique=true, max_length=255) description = models.charfield(max_length=255) content = models.textfield() published = models.booleanfield(default=true) created = models.datetimefield(auto_now_add=true) class meta: ordering = ['-created'] def __unicode__(self): return u'%s' % self.title def get_absolute_url(self): return reverse('blog.views.post', args=[self.slug])
post view:
{% block title %}{{post.title}}{% endblock %} {% block content_blog %} <article> <header> <h1> {{post.title}} </h1> <p> posted on <time datetime="{{post.created|date:"c"}}"> {{post.created|date}} </time> </p> </header> <p class="description"> {{post.description}} </p> {{post.content|safe}} </article> {% endblock %}
url pattern:
urlpatterns = [ url(r'^blog/$', 'blog.views.post', name='blogpage'), url(r'^(?p<slug>[\w\-]+)/$', 'blog.views.post'), ]
view:
from django.conf import settings django.shortcuts import render, get_object_or_404 blog.models import post .forms import contactform django.core.mail import send_mail def index(request): posts = post.objects.filter(published=true) return render(request, 'blog/index.html', {'posts': posts}) def post(request, slug): post = get_object_or_404(post, slug=slug) return render(request, 'blog/post.html', {'post': post}) def contact(request): form = contactform(request.post or none) if form.is_valid(): form_email = form.cleaned_data.get("email") form_message = form.cleaned_data.get("message") form_full_name = form.cleaned_data.get("full_name") subject = 'site contact form' from_email = settings.email_host_user to_email = [from_email, '#'] contact_message = "%s: %s via %s"%( form_full_name, form_message, form_email) send_mail(subject, contact_message, from_email, to_email, fail_silently=false) context = { "form": form, } return render (request, 'forms.html', context)
not sure else need post give guys more details.
i'm using python 3.4.1 , django 1.9 on ubuntu 14.04.
you seem passing arguments browser model attributes except slug, positional argument of function post
. don't see handling when processing request. hence missing positional argument. do elsewhere? here slug=slug
. second slug
come from? should use django tools or javascript/ajax/html-post receive browser. once that, through ajax , json, part of post
request dict()
.
def handle(request): if request.method == 'post' , ( 'module_status' in request.post.keys() ): module_status = request.post['module_status']
Comments
Post a Comment