Reputation: 3
I tried my first django project. The following error occurs
AttributeError: 'tuple' object has no attribute '_meta'
here is my views.py
from django.shortcuts import render, get_object_or_404
from django.utils import timezone
from .models import Post
from .forms import PostForm
# Create your views here.
def post_list(request):
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
return render(request, 'blog/post_list.html', {'posts': posts})
def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
return render(request, 'blog/post_detail.html', {'post': post})
def post_new(request):
form = PostForm()
return render(request, 'blog/post_edit.html', {'form': form})
here is my urls.py
from django.urls import path
from . import views
urlpatterns =[
path('', views.post_list, name='post_list'),
path('post/<int:pk>/', views.post_detail, name='post_detail'),
path('post/new/', views.post_new, name='post_new'),
]
and here my forms.py
from django.forms.models import fields_for_model
from .models import Post
class PostForm(forms.ModelForm):
class Meta:
model = Postfields = ('title', 'text',)
fields = '__all__'
when i exe manage.py runserver, i hit that error. the first error is modelform without either the 'fields' attribute or the 'exclude' i repair it with added
fields = '__all__'
in forms.py
any idea?
i am using python 3 and django 2.2.4
thanks
Upvotes: 0
Views: 996
Reputation: 33359
Looks like a cut-and-paste error.
class Meta:
model = Postfields = ('title', 'text',)
That is supposed to be two separate lines:
class Meta:
model = Post
fields = ('title', 'text',)
Upvotes: 2