-1
from flask import Flask
app=Flask(__name__)
@app.route('/admin')
def admin():
return "the current user is admin"

@app.route('/student')
def student():
  return "the current user is student"

@app.route('/teacher')
def teacher():
  return "the current user is teacher"

@app.route('/user/<name>')
def user(name):
  if name == 'admin':
     return redirect(url_for('admin'))
  if user == 'student':
     return redirect(url_for('student'))
  if user == 'teacher':
     return redirect(url_for('teacher'))
if _name_=='_maiin_':
  app.run(debug=true)

this is the flask code am trying to execute.showing me error of-

  File "C:\Users\Nitish Phutane\Desktop\flask.py", line 1, in <module>
    from flask import Flask
  File "C:\Users\Nitish Phutane\Desktop\flask.py", line 1, in <module>
    from flask import Flask
ImportError: cannot import name 'Flask' from partially initialized module 'flask' (most likely due to a circular import) (C:\Users\Nitish Phutane\Desktop\flask.py)

though i have install flask on my system too.can someone please help me to run this code.

ilias-sp
  • 6,135
  • 4
  • 28
  • 41
  • 1
    you need to call the `flask.py` something else. For example `app.py` – ilias-sp May 19 '22 at 13:56
  • Apart from your main problem, some of your syntax is wrong: The `return` statement in `admin()` should be indented too, plus `true` -> `True` in `app.run()`. – jtlz2 May 19 '22 at 13:56

2 Answers2

0

You have a circular import because your file in named flask.py. Change this to anything else and the problem will be gone.

Phantoms
  • 145
  • 5
-1

I think you have created a file called flask.py, so now it is trying to import Flask module from your own file. Try renaming that file in desktop to something else and try again. It is called circular import, and you should always prevent it from happening.