Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP ERROR 405 #58

Open
HelloGit100 opened this issue May 29, 2019 · 4 comments
Open

HTTP ERROR 405 #58

HelloGit100 opened this issue May 29, 2019 · 4 comments

Comments

@HelloGit100
Copy link

HelloGit100 commented May 29, 2019

Django 2.2.1

The steps are as follows:

  • pip3 install pinax-likes

  • Added 'pinax.likes', to the project's settings.py file,
    then added:

PINAX_LIKES_LIKABLE_MODELS = {
    "app.Post": {}
}
  • Added
re_path(r'^likes/', include(('pinax.likes.urls', 'pinax_likes'), namespace='pinax_likes')),

to the project's urls.py file,

  • Download the files in the https://github.com/pinax/pinax-templates/tree/master/pinax/templates/templates/pinax/likes,

put these html files in /home/www/venv/templates/pinax/likes/,

  • Added
{% load pinax_likes_tags %}
{% likes_widget request.user post %}

to the post.html file,

The console displays the following information:

Method Not Allowed (GET): /likes/like/14:13/
Method Not Allowed: /likes/like/14:13/
[29/May/2019 10:00:00] "GET /likes/like/14:13/ HTTP/1.1" 405 0

  • Then i added <script src="{% static 'eldarion-ajax.min.js' %}"></script> in base.html,

After clicked the icon, the console displays the following information:

Forbidden (CSRF token missing or incorrect.): /likes/like/14:13/
[29/May/2019 10:01:31] "POST /likes/like/14:13/ HTTP/1.1" 403 2513

What are the steps wrong? Thank you!

@KatherineMichel
Copy link
Member

Not sure answer atm, but looks you had similar problem as @agiledesign2.

@KatherineMichel
Copy link
Member

@HelloGit100 Did you end up finding a solution, or unresolved?

@KatherineMichel
Copy link
Member

Hello @agiledesign2 has posted a solution to his issue. Perhaps, this would solve your problem as well: #57

@mikai-com
Copy link

I added this to the html header to solve issue for me
<script src="{% static "js/jquery.min.js" %}" ></script>
<script>
$.ajaxSetup({
beforeSend: function(xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
if (!(/^http:./.test(settings.url) || /^https:./.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
}
});
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants