V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ray1888
V2EX  ›  Python

Django 跨域问题

  •  
  •   ray1888 ·
    ray1888 · 2017-06-23 12:06:34 +08:00 · 1759 次点击
    这是一个创建于 2496 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我现在用 Django 写了一个测试的网页用于测试如果不用模板如何进行前后端信息交互,正常访问成功返回一个 json 数据,在页面中用 jquery 发出请求,出现了浏览器跨域问题,应该如何解决。

    <script> $.get('http://127.0.0.1:8000/index/index',function(data){ alert('data='+data); }); </script>

    浏览器报错 XMLHttpRequest cannot load http://127.0.0.1:8000/index/index. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

    2 条回复    2017-06-23 13:43:17 +08:00
    bestkayle
        1
    bestkayle  
       2017-06-23 12:33:01 +08:00 via Android
    用装饰器
    pixstone
        2
    pixstone  
       2017-06-23 13:43:17 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3101 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:52 · PVG 22:52 · LAX 07:52 · JFK 10:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.