我有一个项目(learning_log),您可以在其中添加主题,在这些主题中可以添加条目。我有一个编辑条目选项,但我也想添加一个删除条目选项。我做了以下事情,但是当我尝试在heroku上加载它时仍然出现内部错误。 :
urls.py
@foreach($estates as $est)
var result = $.ajax({
url: 'https://maps.googleapis.com/maps/api/geocode/json?address={{$est->address}}&key={{env('GOOGLE_MAPS_API')}}'
})
result.done(function(data) {
{{ get required data and save to somewhere }}
});
@endforeach
views.py
import * as firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/database'
import 'firebase/storage'
export default {
actions: {
fetchUserData ({commit, getters}) {
commit('setLoading', true)
firebase.database().ref('/users/' + getters.user.id + '/registerations/').once('value')
.then(data => {
const dataPairs = data.val()
let registeredMeetups = []
let swappedPairs = {}
for (let key in dataPairs) {
registeredMeetups.push(dataPairs[key])
swappedPairs[dataPairs[key]] = key
}
const updatedUser = {
id: getters.user.id,
registeredMeetups: registeredMeetups,
fbKeys: swappedPairs
}
commit('setLoading', false)
commit('setUser', updatedUser)
})
.catch(error => {
console.log(error)
commit('setLoading', false)
})
}
}
}
delete_entry.html
urlpatterns = [
#...
#Page for deleting an entry
path('delete_entry/',views.delete_entry,name='delete_entry'),
]
edit_entries.html
def delete_entry(request, entry_id):
"""Delete an existing entry"""
entry = get_object_or_404(Entry,id=entry_id) #getting the entry object the user wants to delete
topic=entry.topic
check_project_owner() #This is a custom function (I know it works) Making sure the person who wants to delete it is the owner
entry.delete() #Delete the entry
context = {'entry':entry} #I don't even think we need to pass this but I just want to be safe and pass something
return render(request, 'learning_logs/delete_entry.html', context)
答案 0 :(得分:0)
在您的网址格式中,没有参数传递给视图。但是您的视图需要一个名为entry_id
的额外参数。更新您的网址以解决此问题:
url_patterns = [
...
#Page for deleting an entry
path('delete_entry/<int: entry_id >/',views.delete_entry,name='delete_entry'),
]