i want to write form action to call newpost
function from viwes.py
, newpost
function has 2 arguments which are newpost(request,myid)
, but when i tried to write
action="{%url 'newpost' %}"
an error appears like this :
TypeError at /newpost
newpost() missing 1 required positional argument: 'myid'
how can i send this argument in form action ? please tell me
def newpost (request,myid):
blockedperson=[1]
assert isinstance(request, HttpRequest)
print("if1")
print (request.POST.get('postcontent'))
print (type(request.POST.get('postcontent')))
while request.POST.get('postcontent'):
print ("if2")
if myid not in blockedperson :
savepost=post()
savepost.person_id= 437819147
savepost.content=request.POST.get('postcontent')
savepost.p_date=dt.datetime.now()
savepost.save()
else :
blocked="sorry, you are blocked, you can not share a post, for more information contact with IT on 437819147@kku.edu.sa"
return render (request,'home.html',{'block':blocked})
allpost=post.objects.all()
allperson=person.objects.all()
allstudent=student.objects.all()
allteacher=teacher.objects.all()
allcomp=company_rep.objects.all()
return render (request,'home.html',{'posts':allpost , 'person':allperson,'student':allstudent,'teacher':allteacher,'comp':allcomp,'id':myid})
<form name="postbox" action="{%url 'newpost' %}" method="POST" align="center">
{% csrf_token %}
<label>shear your ideas, information, and experience...</label>
<br />
<textarea id="post" name="postcontent" rows="4" cols="50">
</textarea>
<br />
<input style="width: 31%;" type="submit" value="post" name="postsubmit">
</form>
this also my urls file , should i change in it if i add any arguments ?
urlpatterns = [
path('' , app.views.login),
path('newpost' , app.views.newpost,name='newpost'),
path('signup' , app.views.signup,name='signup'),
path('signupteacher' , app.views.signupteacher,name='signupteacher'),
path('signupstudent' , app.views.signupstudent,name='signupstudent'),
path('signupcompany' , app.views.signupcompany,name='signupcompany')
]