I'm a bit of a rookie even in Python, since I'm starting his apprenticeship. I have encountered a problem when it comes to doing a fairly basic "import". I have searched for information on Google, but I do not understand the solutions I have seen very well, that is why I turn to your wisdom.
The error is as follows;
ValueError: Attempted relative import in non-package
Traceback (most recent call last)
File "/Users/usuario/Desktop/miproyecto/hello.py", line 4, in <module>
from .forms import LoginForm # importamos login
ValueError: Attempted relative import in non-package
Well, the folder of my project has the following structure:
And this is the code of my Hello.py file;
from flask import Flask # Creamos objeto flask
app = Flask(__name__)
from flask import render_template, flash, redirect # Creamos objeto
plantilla , flash , etc
from .forms import LoginForm # importamos login
app.config.from_object('config') # Leemos configuracion creada
@app.route('/')
@app.route('/index')
def hello_world():
return 'Hello, World!'
@app.route('/templates')
def templates():
user = {'nickname': 'juan'}
return render_template('index.html',
title='Home',
user=user)
# index view function suppressed for brevity
@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
return render_template('login.html',
title='Sign In',
form=form)
And this one is in my forms.py file;
from flask.ext.wtf import Form
from wtforms import StringField, BooleanField
from wtforms.validators import DataRequired
class LoginForm(Form):
openid = StringField('openid', validators=[DataRequired()])
remember_me = BooleanField('remember_me', default=False)
Thank you very much in advance! Greetings!