2014-06-09 2 views
0

내 html 파일은 .html 파일 디렉토리 (템플릿)와 다른 디렉토리 인 static 폴더의 .js 파일을 참조합니다..js 파일이 개발 서버에 제공되지 않습니다.

GET http://localhost:63342/UniteMessageBoard/templates/%5CUniteMessageBoard%5Cstatic%5Cjquery.js [HTTP/1.1 404 Not Found 1ms] 

하고 스크립트가로드되지 않습니다 내가 .html 파일을 실행할 때 .js 파일 loaded.Problem 내가 로컬 서버에서 응용 프로그램을 실행하면 나는 오류 메시지가있다이기 때문에, 그것을 잘 작동합니다.

이 내 html 코드 :

<!DOCTYPE html> 
<html> 
<head lang="en"> 
<meta charset="UTF-8"> 
<script type="text/javascript" src="\UniteMessageBoard\static\jquery.js"></script> 
<script type="text/javascript" src="\UniteMessageBoard\static\script.js"></script> 

</head> 
<body> 
    <h1> {{ title }} </h1> 
<input type="button" id="submit2" value="get it"> 
</body> 
</html> 

script.js 코드 :

console.log('loaded script.js'); 

$(document).ready(function() { 

$("#submit2").on('click', function (event) { 
    handleClick(); 
}); 

}); 


function handleClick() { 
    alert("We got here"); 
    $.ajax('/', { 
    type: 'GET', 
    data: { 
     fmt: 'json' 
    } 
}); 
} 

main.py 코드 :

JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), 
extensions=['jinja2.ext.autoescape'], 
autoescape=True) 



class MainHandler (webapp2.RequestHandler): 
    def get(self): 

    self.templateValues = {} 
    self.templateValues['title'] = 'jQuery JSON Tutorial 2' 
    template = JINJA_ENVIRONMENT.get_template('templates/base.html') 
    self.response.out.write(template.render(self.templateValues)) 


    app = webapp2.WSGIApplication([ 
    ('/.*', MainHandler) 

    ], debug=True) 
실제로로드되지 않습니다

[HTTP/1.1 200 OK 18ms] 

비록 : 내가 로컬 응용 프로그램을 실행하는 경우

이은 내가 오류 코드입니다.

편집 : 이 내 디렉토리 트리입니다 : 당신은 거의 확실 창 상자를 개발하고

enter image description here

+1

슬래시를 앞으로 만듭니다. 아무도 디렉토리에 백 슬래시를 사용하지 않습니다. – bjb568

+0

믿거 나 말거나, HTML 파일이 템플릿 폴더에있는 경우 작동하는 유일한 방법입니다. 템플릿 폴더 밖에있는 경우,'/ static/jquery.js'는 잘 작동하지만 동일한 문제가 있습니다. –

+0

Ok ... 디렉토리 트리를 게시 할 수 있습니까? – bjb568

답변

0

. 나는 / 대신에 \ 때문에 말할 수 있습니다. 문제는 로컬 호스트에서 실행중인 웹 서버가 /이되기를 원합니다. 따라서 파일을 로컬에서 웹 서버를 통과하지 않고 액세스 할 수 있지만 일단 서버에 연결되면 중단됩니다.

+0

그게 문제라고 생각해. 어떻게 해결할 수 있는지 알아? –

+0

파일 경로에는'/'만 사용해야하며 웹 서버를 통해서만 페이지를 볼 수 있습니다. –

관련 문제