I am creating a forum. When processing URLs, the board ID and board name are displayed. The name is for reading, and the identifier is the board choice. This means that if the name is incorrect or changed, I want to redirect the user to the correct URL. Some searches led me to decorators, but I can not find a single resource explaining how to use them.
...
url(r'^boards/(?P<board_id>\d+)/(?P<board_name>[^/]+)/$', views.board, name='board'),
...
@redirect_if_wrong_boardname
def board(request, board_id, board_name):
...
return render(request, 'forums/board.html', {'board': board})
How to implement the following logic in a designer?
board = Board.objects.all().get(pk=pk)
if (board.name != name):
return redirect(request.get_full_path().replace(name, board.name, 1))
source
share