How To Work With Ajax In Django Using Vanilla JavaScript | Submit Form Without Refresh

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ต.ค. 2024

ความคิดเห็น • 12

  • @alexdin1565
    @alexdin1565 2 ปีที่แล้ว +1

    after watching hundreds of youtube videos the only one who saves my life is you easy perfect and without JQuery thanks man

  • @mildmildfire
    @mildmildfire 2 ปีที่แล้ว

    Awesome video! A lot of useful tips!

  • @davidrosen2705
    @davidrosen2705 3 ปีที่แล้ว +1

    hey i run your project and got few errors, maybe you can help
    1, when you try to add comment as Anonymous user it gives AnonymousUser' object is not iterable.
    2. you need to add author by hand in the admin so you can post comments if you dont do that it says that you cant find the author instance , i think you can maybe do onetoonefield and make it work ?
    would love to knew what your solution is, thank you great content

    • @davidrosen2705
      @davidrosen2705 3 ปีที่แล้ว

      i think the 1 problem is when you try to do the get on the author instance it gives out a a error because it cant find Anonymous user, how would you go about making Anonymous users be able to post, again thanks no much content with fetch on this subject.

    • @selmitech
      @selmitech  3 ปีที่แล้ว +1

      Thanks for your question. First, let me tell you that the tutorial was dedicated only for Fetch API, so I couldn't talk about few things like:
      - Only logged in users can comment.
      So to fix that and to let anonymous users to comment, you can first make the author field not required in the Comment model:
      class Comment(models.Model):
      author = models.ForeignKey(Author, on_delete=models.CASCADE , blank=True, null=True)
      Also, you can add another input to the comment form to hold to anonymous user's name, at least, if you did so, you need to update the Comment model:
      class Comment(models.Model):
      author = models.ForeignKey(Author, on_delete=models.CASCADE, , blank=True, null=True)
      author_anonymous = models.CharField(max_length=50 , blank=True, null=True)
      And for sure you need to update the views to fit these changes.

    • @davidrosen2705
      @davidrosen2705 3 ปีที่แล้ว

      @@selmitech great thanks

  • @achillekabasele8455
    @achillekabasele8455 3 ปีที่แล้ว

    Thanks you for this tutoriel 🥰

    • @selmitech
      @selmitech  3 ปีที่แล้ว

      You're welcome

  • @davidrosen2705
    @davidrosen2705 3 ปีที่แล้ว

    thank you ,that was great

    • @selmitech
      @selmitech  3 ปีที่แล้ว

      Appreciated.

  • @서진형-d2n
    @서진형-d2n 2 ปีที่แล้ว

    wow useful

  • @Supersonic9
    @Supersonic9 3 ปีที่แล้ว

    Spent days trying to figure out how to do this without JQuery, finally cracked it after watching this. Thank you!