-1

Whatever I seem to try (using different secret keys, trying to fix small errors) this error shows when I run my code.

I have tried making small changes to the code such as changing the secret key, fixing indentation, etc. However, I do not understand why my code does not work, so I wanted to ask here.

from flask import Flask, render_template, session, request
from flask_socketio import SocketIO, emit, join_room

app = Flask(__name__)
app.debug = True
app.config['SECRET_KEY'] = 'secretcodehere29403949493'
socketio = SocketIO(app)

@app.route("/template/chat.html/")
def chat():
  return render_template("template/login.html")


@app.route(r'/template/login.html/')
def login():
  return render_template('login.html')


@socketio.on('message', namespace='/chat')
def chat_message(message):
  print("message = ", message)
  emit('message', {'data': message['data']}, broadcast=True)


@socketio.on('connect', namespace='/chat')
def test_connect():
  emit('my response', {'data': 'Connected', 'count': 0})

if __name__ == '__main__':
  socketio.run(app)
  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 183-355-780 (18512) wsgi starting up on http://127.0.0.1:5000

nothing displays in the link it provides in the error here, and localhost:8080 shows nothing.

PepMeow
  • 1
  • 2

2 Answers2

1

Your routes may not be correct. When you call app.route, you're mapping a url to the function.

In your case the urls in your routes are defining: 127.0.0.1:5000/template/chat.html/ and 127.0.0.1:5000/template/login.html/.

Try changing a route to @app.route('/') and then navigating to 127.0.0.1:5000 or localhost:5000

djnz
  • 2,021
  • 1
  • 13
  • 13
  • thanks! that seemed to make the traceback show in there. However, my code still shows a ```jinja2.exceptions.TemplateNotFound: template/login.html```. Does anyone know how I might fix this? (though this is mostly unrelated). Thanks again for your response! – PepMeow Jun 26 '19 at 11:06
0

Concerning your last comment (I can't comment on dylanj.nz's post), the render_template function uses the default templates folder, so there is no need to specify it on your code :)

Thus you should remove template/ in this line: return render_template("template/login.html").

If you want to change the default folder location, add a template_folder instruction in your app = Flask(...).
Example:

app = Flask(__name__, template_folder='application/templates', static_folder='heyanotherdirectory/static')
sodimel
  • 864
  • 2
  • 11
  • 24