Giter VIP home page Giter VIP logo

talkpython / 100daysofweb-with-python-course Goto Github PK

View Code? Open in Web Editor NEW
625.0 29.0 393.0 7.69 MB

Demo code and resources for our 100 Days of Web in Python Course

Home Page: https://training.talkpython.fm/courses/explore_100days_web/100-days-of-web-in-python

Python 3.69% HTML 2.12% CSS 1.19% Mako 0.03% Shell 0.03% Smarty 0.03% JavaScript 92.87% Makefile 0.04% Procfile 0.01%
100daysofcode python web

100daysofweb-with-python-course's People

Contributors

audiolion avatar bbelderbos avatar dependabot[bot] avatar dev-hospa avatar dhenschen avatar ericchou1 avatar geauxtigers avatar gloc-mike avatar hobojoe1848 avatar mikeckennedy avatar pybob avatar serixscorpio avatar shutteritch avatar tbrlpld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

100daysofweb-with-python-course's Issues

Breaking changes apistar from 0.5.41 to 0.6+

Hi, looks like the latest version of apistar (apistar==0.7.2) did away with some features that prohibits the 'from apistar import App' from working. From http://docs.apistar.com/:

Where did the server go?
With version 0.6 onwards the API Star project is being focused as a framework-agnositic suite of API tooling. The plan is to build out this functionality in a way that makes it appropriate for use either as a stand-alone tool, or together with a large range of frameworks.

The 0.5 branch remains available on GitHub, and can be installed from PyPI with pip install apistar==0.5.41. Any further development of the API Star server would likely need to be against a fork of that, under a new maintainer.

Might want to pin down the install version to 0.5.41 in requirements.txt file.

Days 37-40: Intro to Pyramid: Adding the data models

In this section of the course, I copied the bin, data and db code from the 100 Days GitHub repo into my version of the code.

I found that in data/db_session.py, the return value needs to be the attribute factory i.e. DbSession.factory, rather than the method i.e. DbSession.factory().

However, after fixing that issue, I am now confronted with another. In bin/load_base_data.py, the session returned does not have the 'query' attribute!

I created this Gist which shows the error:
https://gist.github.com/gloc-mike/ddb4fb4ca0aa1ba81209623a8858d606.

When I review the session object in the debug console in PyCharm, I can see that 'query' appears in the public_methods tuple (see attached screenshot) but the my watch expression again, shows the attribute error.

Screen Shot 2020-02-24 at 12 51 24

Any ideas to help me resolve this issue would be appreciated.

Days 09-12 Building APIs with Api Star (0.5.x)

009-012-modern-apis-starred/demo/app.py
for function create_car() we define car_id like len(cars)+1 but after first delete_car() it dosn't work!
isn't better to check max(cars.keys())+1 for same task, or something else?

Day 24 - does not work with Flask 2.x

flask run in the folder 021-024-quart-async/your_turn/day_4/cityscape_api/ fails with an error if using a recent version of Flask (v2.0.2) installed from requirements.txt:

  File "/Users/captsolo/Documents/021-024-quart-async/your_turn/day_4/cityscape_api/app.py", line 2, in <module>
    from views import city_api
  File "/Users/captsolo/Documents/021-024-quart-async/your_turn/day_4/cityscape_api/views/city_api.py", line 4, in <module>
    blueprint = flask.blueprints.Blueprint(__name__, __name__)
  File "/Users/captsolo/Documents/021-024-quart-async/your_turn/venv/lib/python3.7/site-packages/flask/blueprints.py", line 197, in __init__
    raise ValueError("'name' may not contain a dot '.' character.")
ValueError: 'name' may not contain a dot '.' character.

The error does not appear if Flask is pinned to an earlier version (e.g. flask==1.1.2).

Day 69-72 Django Rest Framework Swagger error

After coding along the videos in this section of the course. I get a

'AutoSchema' object has no attribute 'get_link' error when going to api/docs.

It turns out you need to put the following into settings.py to get it to work

REST_FRAMEWORK = {
  'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}

Reference: https://www.django-rest-framework.org/community/3.10-announcement/#continuing-to-use-coreapi

It's probably because I am using a newer version of django-rest-framework than is used in the videos?

Days 009-012

Hi,
Postman PUT doesn't seem to be working. I am changing values for an item and pressing send yet the return is an unchanged json while the console outputs:

127.0.0.1 - - [17/May/2019 21:40:41] "PUT /6 HTTP/1.1" 302 -
127.0.0.1 - - [17/May/2019 21:40:41] "GET /6/ HTTP/1.1" 200 -

I am running the server in Pycharm (community) from the terminal with python app.py

Thanks,
Vlad

Days 9-12 API Method: PUT Issue

I am working through "Days 9-12 API Star" in the 100 Days of Web Python course and I am having issues with the PUT method.

I have cross checked my code against the GitHub version and my code looks logically the same but when I test the PUT method using Postman the 'update_car' function is not called/executed.

I have added print statements to the 'update_car' function to confirm this and indeed there is nothing printed in the console. Adding a print to the 'get_car' function however does print to the console.

My sequence of testing is the some as the video i.e. submit a GET request from Postman (for id 55); the submit the PUT request with updated parameters in the body of the request.

I have created a Git of the server output: https://gist.github.com/gloc-mike/03d1b7eda91b3a07ced3c6efa4ce4d34

In that you can see that the GET request was submitted and the print statement shows id 55; then when I submit the PUT request, the server responds with a 302 (redirect?), does not print my debug messages and then performs a GET request (system generated).

I'm on Mac; PyCharm (2019.3.1); virtual environments pipenv and pyenv; Pyton 3.7.4; apistar version is the recommended version. Also tried running it from the terminal (to remove PyCharm from the equation) but I get the same results.

There is a setting in Postman:

Automatically follow redirects
Prevent requests that return a 300-series response from being automatically redirected.

which I have tried turning off (default is on) but apart from that nothing else has been changed in Postman.

The PUT request from Postman:

PUT /55 HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: PostmanRuntime/7.20.1
Accept: */*
Cache-Control: no-cache
Postman-Token: 914028c8-fc63-47f0-a99f-9132150dd2d3,80314209-e775-4466-8bbd-426400394684
Accept-Encoding: gzip, deflate
Referer: http://127.0.0.1:5000/55
Connection: keep-alive
cache-control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

Content-Disposition: form-data; name="manufacturer"

Jeep
------WebKitFormBoundary7MA4YWxkTrZu0gW--,
Content-Disposition: form-data; name="manufacturer"

Jeep
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Content-Disposition: form-data; name="model"

Mountain High II
------WebKitFormBoundary7MA4YWxkTrZu0gW--,
Content-Disposition: form-data; name="manufacturer"

Jeep
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Content-Disposition: form-data; name="model"

Mountain High II
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Content-Disposition: form-data; name="year"

2001
------WebKitFormBoundary7MA4YWxkTrZu0gW--

My pipfile:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
pytest = "*"
apistar = ">=0.5.41,<0.5.1000"

[requires]
python_version = "3.7"

My version of app.py sans the delete method:

import json
from typing import List

from apistar import App, Route, types, validato
![Screen Shot 2019-12-20 at 18 40 08](https://user-images.githubusercontent.com/2324626/71239822-a5454d80-235b-11ea-9c70-7abdec867949.png)
![Screen Shot 2019-12-20 at 18 40 53](https://user-images.githubusercontent.com/2324626/71239826-ad04f200-235b-11ea-8c12-dcbf6ecf2201.png)

rs
from apistar.http import JSONResponse


# helpers
def _load_cars_data():
    with open('cars.json') as f:
        cars = json.loads(f.read())
        # create a dictionary of the form {car_id: car}
        return {car['id']: car for car in cars}


# To load in the cars call the cars helper function
cars_db = _load_cars_data()

# Some constants
VALID_MANUFACTURERS = set([car['manufacturer'] for car in cars_db.values()])
CAR_NOT_FOUND = 'Car not found!'


# Definition - using APIStar's types.Type to get access to validation &
# serialisation
class Car(types.Type):
    # No auto-incrementer available so assign ID in POST - hence the need to
    # use 'allow_null=True' in this code
    id = validators.Integer(allow_null=True)
    manufacturer = validators.String(enum=list(VALID_MANUFACTURERS))
    model = validators.String(max_length=35)
    year = validators.Integer(minimum=1900, maximum=2050)
    # Make something OPTIONAL just add "default=''"
    vin = validators.String(max_length=50, default='')


# API methods
def list_cars() -> List[Car]:
    # cars_db.items() returns key, value tuple so to get the value from the
    # tuple one must use index [1]
    # Wrapping 'car[1]' with Car() serialises it :)  i.e. turn a dictionary
    # into a Car object
    return [Car(car[1]) for car in sorted(cars_db.items())]


def create_car(car: Car) -> JSONResponse:
    # Since no auto-increment available, manually determine the length of the
    # DB and increment by 1
    car_id = max(cars_db.keys())+1
    # Update the ID for the car we want to create with the new ID
    car.id = car_id
    # Store the new car in the DB
    cars_db[car_id] = car
    return JSONResponse(Car(car), status_code=201)


def get_car(car_id: int) -> JSONResponse:
    print(f"GET car: {car_id}")
    car = cars_db.get(car_id)
    # if a car exists, ".get(car_id)" returns the car otherwise returns None
    if not car:
        error = {'error': CAR_NOT_FOUND}
        return JSONResponse(error, status_code=404)
    return JSONResponse(Car(car), status_code=200)


def update_car(car_id: int, car: Car) -> JSONResponse:
    print(f"PUT car: {car}")
    # Check to see if the car exists so it can be updated
    if not cars_db.get(car_id):
        error = {'error', CAR_NOT_FOUND}
        return JSONResponse(error, status_code=404)
    # So it's ok, go ahead and update the car
    car.id = car_id
    cars_db[car_id] = car
    print(f"PUT cars_db[car_id]: {cars_db[car_id]}")
    return JSONResponse(Car(car), status_code=200)


def delete_car(car_id: int) -> JSONResponse:
    pass

routes = [
    Route('/', method='GET', handler=list_cars),
    Route('/', method='POST', handler=create_car),
    Route('/{car_id}/', method='GET', handler=get_car),
    Route('/{car_id}/', method='PUT', handler=update_car),
    Route('/{car_id}/', method='DELETE', handler=delete_car),
]

app = App(routes=routes)

if __name__ == '__main__':
    app.serve('127.0.0.1', 5000, debug=True)

Any help with how I can trace this issue would be greatly appreciated.

Thanks
Michael

Day 46 Django urls.py import include

Just a note, by default project urls.py did not import include method (at least for me when following the steps) so it needs to be explicitly imported.

Default:

from django.urls import path

Add:

from django.urls import path, include

Days 65-68 Heroku - Sendgrid changes

Hello!

I had two errors when trying to send email with sendgrid.

The first seemed to relate to the order of the variables in which I had to change from:
mail = Mail(from_email, subject, to_email, content)
to:
mail = Mail(from_email, to_email, subject, content)

And then the second referred to the response which I had to change from:
response = sg.client.mail.send.post(request_body=mail.get())
to:
response = sg.send(mail)

I also discovered that I didn't need to import Email & Content so the following worked for me:

import sendgrid
from sendgrid.helpers.mail import Mail

sg = sendgrid.SendGridAPIClient(api_key="MY_API_KEY")

from_email = "[email protected]"
subject = "Winter is coming"
to_email = "[email protected]"
content = "Hey Iain, This works much better"

mail = Mail(from_email, to_email, subject, content)

response = sg.send(mail)

print(response.status_code)
print(response.body)
print(response.headers)

Test

Testing access

Day 53 - 56: Django registration_form.html possibly missing action

Hi, I could be wrong, but it 'seems' to me that the registration_form.html downloaded and unzip from repository was missing the view in the action? Maybe some default function in django_registration.backends.activation.urls?

This was the default registration_form.html:

<h2>Sign up today!</h2>
<form class="pure-form pure-form-stacked" method="post" action=".">
  {% csrf_token %}

I followed the instruction video to set up urls.py under mysite, which directs to django_registration.backends.activation.urls; not sure where that urls.py have associated functions in another views.py file somewhere.

I will rewatch the videos again to make sure I did not miss anything. Thanks!

Days 93-100: @api.route ↑↑ shifts

talkpython/100daysofweb-with-python-course/days/093-096-vuejs/movie_svc/views/api_views.py

talkpython/100daysofweb-with-python-course/days/097-100-docker/demo/services/movie_svc/views/api_views.py

@api.route("/api/movie/genre/all") should be placed upper ↑ than @api.route("/api/movie/genre/{genre}")

and

@api.route("/api/movie/top") upper ↑ than @api.route("/api/movie/{imdb_number}")

Day 85 - 88 suggestion: AWS Lambda and API Gateway Limits

I am a big fan of API Gateway + Lambda and have been using it for a while (for example, this blog, https://www.twilio.com/blog/2017/06/build-serverless-api-amazon-web-services-api-gateway.html). But we have hit a few limitations on both Lambda (https://docs.aws.amazon.com/lambda/latest/dg/limits.html) and API Gateway (https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html) as we scale up our services. For lambda, the deployment size limit restricts the libraries we can include; and the API key limit on API Gateway limits the number of unique keys we can distribute per region.

Azure Functions and Azure API Management and GCP equivalents, on the other hand, are more relaxed.

Not promoting one cloud or the other, but if I were to think about deployment today, I would definitely take the limitation on each service into consideration. So wonder if you'd like to make a note or two in the README or what not.

Day 23: openweathermap.org requires API key now

It seems staring October 9th, 2015, openweathermap.org requires API key for access, therefore returning an error:

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.openweathermap.org/data/2.5/weather?zip=90210,us&appid=

Per https://openweathermap.org/faq#error401:
"Starting from 9 October 2015 our API requires a valid APPID for access. Note that this does not mean that our API is subscription-only now - please take a minute to register a FREE account to receive a key."

The location, sun, and events services still work when testing.

Perhaps make a note during screencast to indicate try the other APIs other than weather or take it out completely in example code?

Question: double forward underscores

Hey guys, I'm pretty excited about your course and job you have done to make it, that's really thorough work.

But sometimes I'm getting a bit confused when seeing double underscores in functions/variables names in various 100DaysOfWeb chapters.
I know that those are used as super-private objects or relative, but can you guys explain me as experts, what is reason to not use a single forward underscore as conventional privacy in python but use double underscores?
For instance, please take a look at a code snippet below (chapter 33-36). Can't we use just self._result name instead of self.__result here to mark that it should be a private one?

class switch:
    __no_result = uuid.uuid4()

    def __init__(self, value):
        self._found = False
        self.__result = switch.__no_result

Do you think it's worth to mention that somewhere in a course? thx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.