Vue+django REST Framework to build a fresh electric Business Project: Error information of learning process

Source: Internet
Author: User
Tags install django pip install django

1. Add accurate search function when the error:

views.py

From django_filters.rest_framework import djangofilterbackend  #精确搜索

Class Goodslistviewset (mixins. Listmodelmixin,viewsets. Genericviewset):
    '
    Sixth Edition, the perfect return of Jason Data, code concise enhanced version, depth of custom paging, dynamic and easy binding HTTP submission method: Router.register (R ' goods ', views. Goodslistviewset)
    '
    queryset = Goods.objects.all ()
    serializer_class = Goodsserializer
    pagination _class = goodspagination  #分页
    #精确过滤搜索
    filter_backends = (djangofilterbackend,)
    filter_fields = (' Name ', ' Shop_price ',)

settings.py

#精确搜索
rest_framework = {
    ' default_filter_backends ': (' django_filters.rest_framework. Djangofilterbackend ',)
}

Error message:

Django.template.exceptions.templatedoesnotexist:django_filters/rest_framework/crispy_form.html

The reason is that the tutorial is not registered in the setting.py file: Crispt_form

Solve the problem after adding the app:

Installed_apps = [
    ' Django.contrib.auth ',
    ' django.contrib.contenttypes ', '
    django.contrib.sessions ',
    ' django.contrib.messages ',
    ' django.contrib.staticfiles ', '
    users.apps.UsersConfig
    ', ' Djangoueditor ',
    ' goods ', '
    trade ',
    ' user_operation ',
    ' xadmin ',
    ' crispy_forms ',
    # DRF configuration
    ' rest_framework ',
    #精确搜索
    ' django_filters ',
]

2.Vue project, when a single interface is debugged

Change the domain name of the Vue interface to local

Let Local_host = ' http://127.0.0.1:8000/';

Get catalog Information
Export Const GetCategory = params => {
  if (' id ' in params) {return
    axios.get (' ${local_host}/ categorys/' +params.id+ '/');
  }
  else {return
    axios.get (' ${local_host}/categorys/', params);
  }
};

Page Error:
mock.js:8359 Get Http://127.0.0.1:8000//categorys/net::ERR_CONNECTION_REFUSED

Reason: The local server is not turned on, and continue to error after opening:
Failed to load http://127.0.0.1:8000//categorys/: No ' Access-control-allow-origin ' header is present on the requested Reso Urce. Origin ' http://localhost:8080 ' is therefore not allowed access. The response had HTTP status code 404.

Reason: Browser and server do not allow Cross-domain Workaround: Set server cross domain installation pip install django-cors-headers server settings.py Settings app
    #跨域
    ' Corsheaders ',

settings.py
middleware = [
    ' Corsheaders.middleware.CorsMiddleware ',
    ...
]
Add under middleware of settings.py
Cors_origin_allow_all = True


Solve



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.