This repository is now DEPRECATED. We are no more maintaining the code here. You can checkout our Full stack Nanodegree for an updated experience.
Solution Code to Full Stack Foundations (ud088)
Solution Code to Full Stack Foundations (ud088)
This repository is now DEPRECATED. We are no more maintaining the code here. You can checkout our Full stack Nanodegree for an updated experience.
Solution Code to Full Stack Foundations (ud088)
Need to convert into bytes , then its printing.
message = ""
message += "Hello!"
#message="Hello World"
# have to convert the string in to Bytes while writing
self.wfile.write(bytes(message,"utf8")
print (message)
Hi Lorenzo,
just wondering, quick query/question ?
I learned a lot with this course and wondering how can I implement login/registration feature other than OAuth and what would be the best package that I can use. please suggest
problem statement/features I am trying to implement in my web app
Appreciate it.
MenuID doesn't get used on the template that it renders. Why pass it over?
Python Version: Python 3.7.5
O.S : Ubuntu 18.04.5
I'm not using vagrant setup. Any help appreciated.
Error :
Error response
Error code: 404
Message: File not found.
Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.
Webserver file code:
`from http.server import BaseHTTPRequestHandler,SimpleHTTPRequestHandler, HTTPServer
class webhandler(SimpleHTTPRequestHandler):
def do_Get(self):
try:
if self.path.endswith('/hello'):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
output = ''
output +=f"<html><body>Hello!</body></html>"
self.wfile.write(bytes(output,"utf8"))
return
except IOError:
self.send_error(404,"File not found %s" % self.path)
def main():
try:
port = 8080
server = HTTPServer(("",port),webhandler)
print("Web server running on port %s" % port)
server.serve_forever()
except KeyboardInterrupt:
print("^c entered Stopping webserver...")
server.socket.close()
if __name__=='__main__':
main()`
I got this error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1836, in call
return self.wsgi_app(environ, start_response)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functionsrule.endpoint
File "/vagrant/web_server/webbyflask.py", line 18, in restaurantMenuJSON
return item.serialize
AttributeError: 'MenuItem' object has no attribute 'serialize'
this my webbyflask.py
from flask import Flask, render_template, request, url_for, redirect, flash, jsonify
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Restaurant, MenuItem
from flask.templating import render_template
app = Flask(__name__)
engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
@app.route('/restaurants/<int:restaurant_id>/menu/<int:menu_id>/JSON')
def restaurantMenuJSON(restaurant_id, menu_id):
item = session.query(MenuItem).filter_by(id = menu_id).one()
return item.serialize
and this is my database_setup.py
import sys
import os
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
Base = declarative_base()
class Restaurant(Base):
__tablename__ = 'restaurant'
name = Column(String(80), nullable = False)
id = Column(Integer, primary_key = True)
class MenuItem(Base):
__tablename__ = 'menu_item'
name = Column(String(80), nullable = False)
id = Column(Integer, primary_key = True)
course = Column(String(250))
description = Column(String(250))
price = Column(String(8))
restaurant_id = Column(Integer, ForeignKey('restaurant.id'))
restaurant = relationship(Restaurant)
@property
def serialize(self):
return {
'name': self.name,
'description': self.description,
'id': self.id,
'price': self.price,
'course': self.course,
}
editedItem.description = request.form['name']
it should be
edititem.description = request.from['description']
On the line 167 of :https://github.com/udacity/ud330/blob/master/Lesson2/step2/project.py
app.secret_key = 'super_secret_key'
What is that mean?
line 62. deletemenuitem.html instead of 'deleteconfirmation.html'
Should be:
editedItem.description = request.form['description']
I have tried doing the Running the Webserver Quiz part using vagrant and virtual box (I'm using Windows 8). But although the file itself runs, the output "Hello" isn't displayed in the browser. I also tried running the file without vagrant but instead I get this
`Error response
Error code: 501
Message: Unsupported method ('GET').
Error code explanation: HTTPStatus.NOT_IMPLEMENTED - Server does not support this operation.`
I don't know what to do, please help. Thank you in advance.
Line 75 - 76 in Lesson-3/12_Edit-Menu-Form/project.py
the current code is:
return render_template(
'editmenuitem.html', restaurant_id=restaurant_id, MenuID=MenuID, item=editedItem)
the variable returned from this function is item
. But in the editmenuitem.html
, the variable used is i
. I think changing item
to i
can solve the problem.
would you like me to do it ?
It would be better if return statement can be added at the end of if statement for edit to stop execution flow.
Not a big deal, but you're not calling commit() on line 364, so the Chanterelle toast isn't getting in its own commit. Add the "()".
in render_templeate menu.html should be put in single quote 'menu.html'
Traceback (most recent call last):
File "database_setup.py", line 44, in
Base.metadata.create_all(engine)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/schema.py", line 4321, in create_all
ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2057, in _run_visitor
with self._optional_conn_ctx_manager(connection) as conn:
File "/usr/lib/python2.7/contextlib.py", line 17, in enter
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2049, in _optional_conn_ctx_manager
with self._contextual_connect() as conn:
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2251, in _contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2289, in _wrap_pool_connect
e, dialect, self
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1555, in handle_dbapi_exception_noconnection
sqlalchemy_exception, with_traceback=exc_info[2], from=e
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 2285, in _wrap_pool_connect
return fn()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/base.py", line 363, in connect
return _ConnectionFairy._checkout(self)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/base.py", line 773, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/base.py", line 492, in checkout
rec = pool._do_get()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/impl.py", line 238, in _do_get
return self._create_connection()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
return _ConnectionRecord(self)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/base.py", line 437, in init
self.__connect(first_connect_check=True)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/base.py", line 657, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 69, in exit
exc_value, with_traceback=exc_tb,
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/pool/base.py", line 652, in __connect
connection = pool._invoke_creator(self)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py", line 114, in connect
return dialect.connect(*cargs, **cparams)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 490, in connect
return self.dbapi.connect(*cargs, **cparams)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
Hi, was working through the course lessons and noticed the following:
Html file is here: https://github.com/lobrown/Full-Stack-Foundations/blob/master/Lesson-3/14_Delete-Menu-Item/deletemenuitem.html
Project.py is here: https://github.com/lobrown/Full-Stack-Foundations/blob/master/Lesson-3/15_Delete-Menu-Item-Solution/project.py#L62
I had to change this line 62 in project.py:
"return render_template('deleteconfirmation.html', item=itemToDelete)"
Changed to match the html file name and variable requirements for given template html.
“return render_template('deletemenuitem.html',restaurant_id=restaurant_id, item=itemToDelete)”
Also I did a search on This repository and there is no files named deleteconfirmation.html yet it is referenced it some of your scripts.
The CSS references an img3.jpg which is not in the list of files on github. Please add it.
The code written is listed like this on lines 16, 29 and 52:
'''<form method='POST' enctype='multipart/form-data' action='/hello'><h2>What would you like me to say?</h2><input name="message" type="text" ><input type="submit" value="Submit"> </form>'''
Corrected code should look like this to prevent issues:
"<form method='POST' enctype='multipart/form-data' action='hello'><h2>What would you like me to say?</h2><input name='message' type='text'/><input type='submit' value='Submit'/></form>"
created this ticket to help others - posting the webserver.py python3 version in the resolution.
Not sure if it's intentional but the restaurantMenu method exists twice and the redirect module isn't amongst the import statements.
After running the database_setup file, A new db file is created with create queries and a lot of weird characters. The psql cannot execute this file.
/Lesson-3/14_Delete-Menu-Item/deletemenuitem.html has the following syntax (line 15):
href = "url_for{{('restaurantMenu', restaurant_id = restaurant_id')}}"> Cancel
The above code gave a error but the following change in syntax worked (moving the curly braces):
href = "{{url_for('restaurantMenu', restaurant_id = restaurant_id')}}"> Cancel
Final project has syntax errors and is not PEP8
change the delete and update href wrap to double quotes plz
Function restaurantMenu is defined twice in the file https://github.com/udacity/Full-Stack-Foundations/blob/master/Lesson-3/12_Edit-Menu-Form/project.py
It is better to change "placeholder" attribute with value, so that user will already have the initial text, which they can edit. The same with editRestaurant.html.
Redirect to the other site code should be 302 but not 301。
Just wanted to check on line 28 in the code:
Lesson-3/11_form-requests-and-redirects/project.py
line 28: return redirect(url_for('restaurantMenu', restaurant_id = restaurant_id))
should it be 'HelloWorld' instead of 'restaurantMenu'?
Thanks,
The link from menu.html to create new item form is not rendered by Flask.
Hi, I noticed some errors in the final code.
In project.py:
In deletemenuitem.html
In editmenuitem.html
I downloaded webserver.py from lesson 2. The page showed up with an input box. However, after submitting, the website is blank. The console responded 301 to show I posted successfully. What is the issue here?
Kindely 😃 self.wfile.write(message.encode())to write message over connection network must be encoded
not self.wfile.write(message) i have issue and after make encode it's run
self.wfile.write(message.encode())
👍
I was having issues and looked at the solution for this code on line 32: self.wfile.write(output)
I had to include an .encode()
for it to run. I wanted to submit this suggestion. It was the only way I could get my output on the screen.
Line 32: self.wfile.write(output.encode())
In Lesson-3/11_form-requests-and-redirects/project.py
, line 36 you missed a closing mark:
Currently:
@app.route('/restaurant/<int:restaurant_id>/<int:menu_id/edit/')
Should be:
@app.route('/restaurant/<int:restaurant_id>/<int:menu_id>/edit/')
All of the provided code via Udacity has ran smoothly for me until I got to Lesson 3-3 Running Your First Flask Application. I copied and pasted the 'project.py' code directly from Github. Upon running the code via 'python project.py' in the terminal, I get the following error message. I have no clue what it means. Can someone help? Thanks!
vagrant@vagrant:/vagrant/Database_Files$ python project.py
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.