D
D
Dmitry Vyatkin2015-12-09 21:10:17
Django
Dmitry Vyatkin, 2015-12-09 21:10:17

What are hooks in django and in general in the context of web development?

Explain clearly what it is and why?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
SpyceR, 2015-12-09
@SpyceR

Hooks - anchors for code.
I don’t know how in Django, but in many CMS it is used to bind another code to a specific point in the code.
For example in Wordpress: in the footer file you have do_action(footer_hook)
Then you can add add_action(footer_hook, hook_function) in the functions.php file (where all functions are written)
And when the site and footer are loaded, the function that is "attached" will be executed ( hooked) to the action footer_hook

U
un1t, 2015-12-09
@un1t

Xs, I remember there were hooks in Drupal. And in dzhang something did not meet such. It's still in the git. Do you mean signals?

O
OnYourLips, 2015-12-09
@OnYourLips

Most likely it is a perverse translation of Event Listeners.

A
Alexander Pupkin, 2015-12-09
@sakrab

In Drupal it looks like this:

function hook_form_alter() {
    //code
}

т.е. вcтроеная функция самого Drupala.
Ну если пишешь свой модуль, то можешь переопределить эту функцию:
function MYMODULE_form_alter() {
    //code
}

Как то так...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question