flaskweb开发书中:
1 from flask import render_template, redirect, request, url_for, flash
2 from flask_login import login_user, logout_user, login_required,current_user
3 from . import auth
4 from .. import db
5 from ..models import User
6 from ..email import send_email
7 from .forms import LoginForm,RegistrationForm
上述.和..起到什么作用呢?
tree是这样的
├── app
│ ├── auth
│ │ ├── forms.py
│ │ ├── forms.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── views.py
│ │ └── views.pyc
│ ├── email.py
│ ├── email.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── main
│ │ ├── errors.py
│ │ ├── errors.pyc
│ │ ├── forms.py
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── views.py
│ │ └── views.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── static
│ │ └── favicon.ico
│ └── templates
│ ├── 404.html
│ ├── 500.html
│ ├── auth
│ │ ├── email
│ │ │ ├── confirm.html
│ │ │ └── confirm.txt
│ │ ├── login.html
│ │ ├── register.html
│ │ └── unconfirmed.html
│ ├── base.html
│ ├── index.html
│ └── mail
│ ├── new_user.html
│ └── new_user.txt
├── config.py
├── config.pyc
├── LICENSE
├── manage.py
├── README.md
├── requirements.txt
└── tests
├── __init__.py
├── test_basics.py
└── test_user_model.py
这个脚本在app/auth/下
.. and . are the meaning of this directory and the superior directory. You must be able to use
cd ..
rightWriting like this in python also means the same thing, take
As an example
Compared to auth, models can only be found by going back to the upper layer first.
from . is to search for module files from the directory where the current file is located,
from .. is the directory superior to the directory where the current file is located.
Refer to the official instructions here: https://docs.python.org/2/tut...
from xx import xxx
import xx
Python uses this import module. The module can be a function, class, or collection.
This method is mainly to differentiate naming. If the called module function names are repeated, they can be distinguished.
import xx calls the entire package.
from xx import xxx calls a function in the package.
For example:
I want a school bag import bag
I want a book in the school bag from bag import book
The answer you want is not here. Look for a basic Python book and read carefully about module import.