selam arkadaşlar ben firmada yazılımcıyım 2 aylık bir projem var
pythonu 2 aydır öğreniyorum biyerlere geldim sürekli kurs alıyor kendimi geliştiriyorum
django tabanlı şirketimin intranet projesini kendim yapıyorum
ben Events veritabanına bağlı comment sistemi eklemeye çalıştım yani Events içinde belirli evente yorum yazıp evente göre listelemek yorumu fakat hata bu
TypeError at /
home() missing 1 required positional argument: ‘event_id’
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/ |
Django Version: | 4.1.3 |
Exception Type: | TypeError |
Exception Value: | home() missing 1 required positional argument: ‘event_id’ |
Exception Location: | C:\Users\dogukan.yegin\Desktop\uygulamalar\KMO.venv\Lib\site-packages\django\core\handlers\base.py, line 197, in _get_response |
Raised during: | Events.views.home |
Python Executable: | C:\Users\dogukan.yegin\Desktop\uygulamalar\KMO.venv\Scripts\python.exe |
Python Version: | 3.11.0 |
Python Path: | [‘C:\Users\dogukan.yegin\Desktop\uygulamalar\KMO’, ‘C:\Users\dogukan.yegin\AppData\Local\Programs\Python\Python311\python311.zip’, ‘C:\Users\dogukan.yegin\AppData\Local\Programs\Python\Python311\DLLs’, ‘C:\Users\dogukan.yegin\AppData\Local\Programs\Python\Python311\Lib’, ‘C:\Users\dogukan.yegin\AppData\Local\Programs\Python\Python311’, ‘C:\Users\dogukan.yegin\Desktop\uygulamalar\KMO\.venv’, ‘C:\Users\dogukan.yegin\Desktop\uygulamalar\KMO\.venv\Lib\site-packages’] |
Server time: | Thu, 12 Jan 2023 14:30:42 +0000 |
views.py
def home(request,event_id):
event = get_object_or_404(Events, id=event_id)
comments = Comment.objects.filter(post=event)
events = Events.objects.all()
photos = PostImages.objects.all()
event_filter = EventFilter(request.GET, queryset=events)
photo_filter = PhotoFilter(request.GET, queryset=photos)
form = CommentForm()
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
if request.user.is_authenticated:
comment = form.save(commit=False)
comment.post = event
comment.user = request.user
comment.save()
messages.success(request, "Comment added!")
else:
messages.error(request, "You must be logged in to comment.")
return redirect('home', event_id)
data = {'event': event, 'comments': comments, 'events': events, "event_filter": event_filter, 'photos': photos, "photo_filter": photo_filter, "form": form}
return render(request, 'index.html', data)
urls.py
rlpatterns = [
path("personel_girisi", views.personel_girisi),
path('', views.home, name='home'),
path('event/<int:event_id>/', views.home, name='home'),
path("gallery",views.gallery, name='gallery'),
path('like/<int:pk>/', views.like, name='like'),
path('dislike/<int:pk>/', views.dislike, name='dislike'),
]+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)```
forms.py
class CommentForm(forms.ModelForm):
event = forms.ModelChoiceField(queryset=Events.objects.all(), required=True)
event_id = forms.IntegerField(widget=forms.HiddenInput())
content = forms.CharField(widget=forms.Textarea(attrs={
'class': 'md-textarea form-control',
'placeholder': 'comment here ...',
'rows': '4',
}))
class Meta:
model = Comment
fields = ('content', 'event')
Create your models here.
class Events(models.Model):
Subject = models.CharField(max_length=50, blank=True)
tags = TaggableManager()
def __str__(self):
return 'Events: {}'.format(self.Subject)
class Comment(models.Model):
user=models.ForeignKey(User, on_delete=models.CASCADE)
date=models.DateTimeField(auto_now_add=True)
post=models.ForeignKey(“Events”, on_delete=models.CASCADE,default=None,null=True)
content= models.TextField()
def str(self):
return self.user.username
yardımcı olurmusunuz?