/ test / DEF230548 /的ConnectionError

时间:2018-07-03 02:36:12

标签: python django

/ test / DEF230548 /处的ConnectionError HTTPConnectionPool(host ='test',port = 80):URL超过最大重试次数:/ test / DEF230548 /(由NewConnectionError(':导致无法建立新连接:[Errno 8]节点名或服务名未提供,或者未知) ',)) 错误发生

我正在制作Django app.Django版本是1.8。 我写在urls.py

[
  {
    "_id": {
      "$oid": "5b37e456565971258da97d5e"
    },
    "isAdmin": false,
    "name": "montygoldy",
    "email": "montygoldy@gmail.com",
    "password": "$2a$10$zWbxV0Q3VPUxRC6lzJyPBec3P/8zYBaSCTJ2n88Uru3zzFlicR2rq",
    "__v": 0
  }
]

在views.py

from django.conf.urls import url
from app import views

urlpatterns = [
    url(r'^$', views.home, name=‘home’),
    url(‘test/(?P<id>[\w.-]+)/', views.test, name=‘test’),
]

当我访问http://127.0.0.1:8000/test/DEF230548/时,发生错误。 在终端中显示了print(“ HERE1”),但未创建static / data /。不能调用2个8000端口的url吗?应该如何解决?

完整追溯是

def home(request):
     ・
    ・
    ・
    test(request,id)
    template = loader.get_template('top.html')
    return HttpResponse(template.render(request))

def test(request,id):
    try:
        dir_path = "static/data/“
        print("HERE1")
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)

    except requests.ConnectionError as e:
        print("HERE2")
        print(e)
        template = loader.get_template('data.html')
        return HttpResponse(template.render(request))

1 个答案:

答案 0 :(得分:0)

对于您的urls.py,将标点符号'替换为',然后重试:

from django.conf.urls import url
from app import views

urlpatterns = [
    url(r'^$', views.home, name='home'),
    url(r'^test/(?P<id>[\w.-]+)/$', views.test, name='test'),
]