0

I'm new to django, I follow a tutorial from udemy (tweetme) While setting-up rest_framework to load serialized data as json, I get these errors :

TypeError: e.indexOf is not a function in : jquery-3.3.1.min.js:2:82466

and :

Source map error: request failed with status 404 Resource URL: http://127.0.0.1:8000/static-directory/rest_framework/css/bootstrap.min.css Source Map URL: bootstrap.min.css.map

I just used serialized classes and simple view to display my data, (I got the display but still have the error)

The output in my console:

[17/Jun/2018 08:50:24] "GET / HTTP/1.1" 200 5324

[17/Jun/2018 08:50:24] "GET /static-directory/rest_framework/js/csrf.js HTTP/1.1" 304 0 [17/Jun/2018 08:50:24] "GET /static-directory/rest_framework/js/ajax-form.js HTTP/1.1" 304 0 [17/Jun/2018 08:50:24] "GET /static-directory/rest_framework/js/jquery-3.3.1.min.js HTTP/1.1" 304 0

.

//other .css and .js with a success GET (200 and 3xx)

.

[17/Jun/2018 08:50:24] "GET /static-directory/rest_framework/css/bootstrap.min.css HTTP/1.1" 200 121200

[17/Jun/2018 08:50:24] "GET /static-directory/rest_framework/img/grid.png HTTP/1.1" 200 1458 [17/Jun/2018 08:50:25] "GET /static-directory/rest_framework/css/bootstrap.min.css.map HTTP/1.1" 404 1764

Here is my code:

in "/tweets/models.py":

from django.conf import settings
from django.db import models

class Tweet(models.Model):
    user        = models.ForeignKey(settings.AUTH_USER_MODEL, default = 1,on_delete=models.CASCADE)
    content     = models.CharField(max_length=150, default="")
    boolean     = models.BooleanField(default=True)
    timestamp   = models.DateTimeField(auto_now_add=True)
    updated     = models.DateTimeField(auto_now=True)

in "/tweets/api/views.py":

from rest_framework import generics
from .serializers import TweetSerializer
from tweets.models import Tweet

class TweetListApiView(generics.ListAPIView):
    serializer_class    = TweetSerializer

    def get_queryset(self):
        return Tweet.objects.all()

in "/tweets/api/serializers.py":

from rest_framework import serializers
from tweets.models import Tweet

class TweetSerializer(serializers.ModelSerializer):
    class Meta:
        model   = Tweet
        fields  = [
        "user",
        "content",
        "boolean",
        "timestamp"
        ]

in "/tweets/api/settings.py":

STATIC_URL = '/static-directory/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static-storage"),
]

STATIC_ROOT=os.path.join(os.path.dirname(BASE_DIR), "static-serve")

N.B: I have no js code I said that I used the code above which uses js from the framework "rest_framework" of django (The framework uses jquery library) (sorry for the wrong answer, I was on my mobile)

Is it a framework issue?

I started a new (clean) django project and did the startup tutorial for django rest framework in : http://www.django-rest-framework.org

by adding this in my urls.py:

from django.conf.urls import url, include
from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets

# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')

# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)

# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]

I thank you for your answers

2
  • 2
    That is clearly a JavaScript error, so don't you think you should post your JavaScript code? Commented Jun 16, 2018 at 21:52
  • Please don't post pictures of errors, include the error as text instead. Commented Jun 17, 2018 at 0:57

1 Answer 1

2

Fixed the TypeError: after figuring out that it was a compatibility problem, I tried to install djangorestframework 3.7.4 which is the first version supporting Django 2.0 (the versions 3.7.5, 3.7.6 and 3.7.7 are also compatible) N.B: I was using djangorestframework 3.8.2

Fixed the missing bootstrap.min.css 404 not found: I had this on my html :

<script src="{% static '/script/ajax.js' %}"></script>

the correction was to change the link to :

<script src="{% static 'script/ajax.js' %}"></script>

I thank you all for your support

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.