即使返回HttpResponse(),“ str”对象也没有属性“ get”,

时间:2018-07-27 15:14:34

标签: python django

我目前正在将Flask应用程序移植到Django。我在views.py

中有一个向此功能发出请求的URL
def run_by_marker(request, test_marker):
    # TODO: find a perm location for the report to live within the application 
    file_path = '/json_test_results' 

    # only allow specific strings to be passed in by the user
    if test_marker not in ['smoke', 'regression']: # update as more tages are introduced to the project
        return 'You have entered an invalid term. Please use either smoke of regression.'

    # run pytest command with self contained reporting
    pytest_command = pytest.main(['-v', '--json-report', '-m', test_marker])
    report = send_from_directory(os.environ['PWD'], '.report.json')
    # convert report to json
    report_json = json_report('.report.json')
    # send report json to method
    insert_test_data(report_json)
    # return test report to user
    return HttpResponse(report)

以下是网址:

urlpatterns = [
    path('run_test_by_mark/<test_marker>/', views.run_by_marker, name='run_by_marker'),

当我调用该URL时,出现以下错误:

AttributeError at /run_test_by_mark/x/
'str' object has no attribute 'get'
Request Method: GET
Request URL:    http://0.0.0.0:8969/run_test_by_mark/x/
Django Version: 2.0.7
Exception Type: AttributeError
Exception Value:    
'str' object has no attribute 'get'

这里的另一个用户有一个similar issue,据我所知,它已经正确设置了东西

这是我第一次使用Django,所以我仍然学到很多东西。这里有什么明显的地方我做错了吗?

0 个答案:

没有答案