案例我在/ notes / get / 1 /其中id = 1,并且我在note.html中创建了一个“Delete Note”链接。 我需要它从数据库和应用程序中删除当前的注释并重定向到/ notes / all。 你可以帮我用def delete中的代码吗?
models.py:
class Note(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
cr_date = models.DateTimeField(auto_now_add=True)
urls.py:
urlpatterns = patterns('',
url(r'^all/$', 'note.views.notes'),
url(r'^get/(?P<note_id>\d+)/$', 'note.views.note'), #
url(r'^language/(?P<language>[a-z\-]+)/$', 'note.views.language'), #
url(r'^create/$', 'note.views.create'),
url(r'^delete/$', 'note.views.delete'), <--------------------------
url(r'^search/$', 'note.views.search_titles'),
)
views.py:
def delete(??????):
????? <-------------------------------------------
return HttpResponseRedirect('/notes/all')
Case I am in /notes/get/1/ where id=1 and I have created a "Delete Note" link in note.html. I need it to delete the current note from database and app and redirect to /notes/all. Can you help me with the code in def delete?
models.py:
class Note(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
cr_date = models.DateTimeField(auto_now_add=True)
urls.py:
urlpatterns = patterns('',
url(r'^all/$', 'note.views.notes'),
url(r'^get/(?P<note_id>\d+)/$', 'note.views.note'), #
url(r'^language/(?P<language>[a-z\-]+)/$', 'note.views.language'), #
url(r'^create/$', 'note.views.create'),
url(r'^delete/$', 'note.views.delete'), <--------------------------
url(r'^search/$', 'note.views.search_titles'),
)
views.py:
def delete(??????):
????? <-------------------------------------------
return HttpResponseRedirect('/notes/all')
原文:https://stackoverflow.com/questions/19382664
请发表评论