Part 2: Web Development With Python

You can access this book in different file formats that are optimized to give you a great reading experience, no matter which device you are using. The options are as follows:

DRM-free PDF optimized for reading on tablets and computers:

ePub version for e-reader devices and phones/tablets:

Mobipocket (.mobi) version for reading on Kindle devices:

Tw1que on March 26, 2020

You guys should consider adding numbered lines to the code snippets in the book. I am currently working on the debugging section of the book and it is sort of confusing without numbered lines.

Tw1que on March 27, 2020

In the course I noticed that the <label **for=""***> is pointing to a non-existing id (mail and name are used, where password and username should have been used.

<label for="***password***">Password:</label>
        <input type="text" id="password" name="password" 
                value="{{ request.form.password }}"/>

Tw1que on March 29, 2020

Why has the Class to declare the table models an init?

`class Task(db.Model):

__tablename__ = 'tasks'

task_id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
due_date = db.Column(db.Date, nullable=False)
priority = db.Column(db.Integer, nullable=False)
status = db.Column(db.Integer)

def __init__(self, name, due_date, priority, status):

    self.name = name
    self.due_date = due_date
    self.priority = priority
    self.status = status

def __repr__(self):

    return '<name {0}>'.format(self.name)`

The SQLAlchemy documentation states:

Note how we never defined a init method on the User class? That’s because SQLAlchemy adds an implicit constructor to all model classes which accepts keyword arguments for all its columns and relationships. If you decide to override the constructor for any reason, make sure to keep accepting kwargs and call the super constructor with those kwargs to preserve this behavior:

Tw1que on March 29, 2020

What is the use of task_id = IntegerField()? Is this not redundant due to auto-increment? It’s not used in the HTML either; there is no field for the user to submit data…

class AddTaskForm(Form):

    task_id = IntegerField()
    name = StringField(
        'Task Name', 
        validators=[DataRequired()]
        )
    due_date = DateField(
        'Date Due (mm/dd/yyyy)',
        validators=[DataRequired()], format='%m/%d/%Y'
        )
    priority = SelectField(
        'Priority',
        validators=[DataRequired()],
        choices=[
            ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'),
            ('6', '6'), ('6', '6'), ('8', '8'), ('9', '9'), ('10',' 10')
            ]
        )
    status = IntegerField('Status')

Tw1que on March 31, 2020

I just started on Error handling page 354, and it seems that the browser catches the error before the logic does. Is this a feature in browsers not present at the time of writing the lessons?

And another question: Why does the first return, return a render_template and the second return, return a redirect?

@app.route('/add/', methods=['GET', 'POST'])
@login_required
def new_task():
    error = None
    form = AddTaskForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            new_task = Task(
                form.name.data,
                form.due_date.data,
                form.priority.data,
                datetime.datetime.utcnow(),
                '1',
                session['user_id']
            )
            db.session.add(new_task)
            db.session.commit()
            flash('New entry was successfully posted. Thanks.')
            return redirect(url_for('tasks'))
    return render_template(
        'tasks.html',
        form=form,
        error=error,
        open_tasks=open_tasks(),
        closed_tasks=closed_tasks()
    )

Tw1que on March 31, 2020

Sorry for completely filling this page up with comments; but here is another question:

Why on page 361 do we create a helper function “flash_errors”? It seems that it’s not called anywhere..

Aqhail Mihailov on April 17, 2020

Hello, i had an error in django ecommerce. When i fire up server, in browser, i got an error “Reverse for ‘contact’ with arguments ‘()’ and keyword arguments ‘{}’ not found. 0 pattern(s) tried: []” (i just copied base.html and index.html from github templates). Then i delete <div class=”container-narrow”> in base.html ,and it works as shown in page 564 (RealPythonPart2.pdf).

Aqhail Mihailov on April 20, 2020

there is one more mistake on page 572 - in contact/views.py request.method must be ‘GET’ not ‘POST’(as written in book) if request.method == ‘GET’: form = ContactView(request.GET) and in templates/contact.html - we must change in <form> method to “GET” <form action=”.” method=”GET” enctype=”multipart/form-data”> {% csrf_token %} {{ form.as_p }} <br> <button type=”submit” class=”btn btn-primary”>Submit</button> </form>

I’m wondering, why the content of book is looking so charade. I have not so much time to unravel basic content. It upsets

piotrmstaniszewski on April 23, 2020

Hi guys, @Tw1que & @Aqhail Mihailov is anyone answering your questions?

Tw1que on April 25, 2020

@piotrmstaniszewski I have not had a reply yet.

Saoirse on May 29, 2020

Has anyone figured out how to get help with this course?

katharinaannawilding on July 2, 2020

The link on page 36 (eepurl.com/xnT3b) does not work, i.e. it redircts to mailchimp.com

mdnauman on July 8, 2020

I am on trying to automate the deployment using Fabric as given on page 258 of the RealPythonPart2 book but it is not working. I have installed latest Fabric 2.5 and using Python 3.8.3 on MAC and also my default shell is ZSH. But when I run “fab” command it uses “bash” and can’t find python file. Can you please help me how to configure Fabric to use ZSH instead of BASH?

mdnauman on July 10, 2020

Hey guys,

In case it helps someone, I was able to solve the issue by installing fab3 which seems to be unofficial version of Fabric but it workes fine.

knetheiner on Jan. 5, 2021

def flash_errors(form):
    ...

page 167 in book 2. When and how is this function called?

I also don’t get the point about the verification on the forms side. Why are not all failed verifications displayed to the user.

Example:

entering 01.01.2021 instead of 01/01/2021 displays this field is required instead of wrong format.

Niko on May 4, 2021

Hello guys,

Has anyone got any info on when the revised Part 2 of this course will see the daylight?

You must own this product to join the conversation.