0

I was able to get compare to work properly via the terminal though the web application keeps throwing "Cannot POST /compare" and index.html doesn't show any CSS. The page shows the layout info but no CSS. It does submit but doesn't post while throwing the above error.

Here is an image of the page:

enter image description here

Here is another image showing the error:

enter image description here

And here is the form coded in html:

{% extends "layout.html" %}

{% block body %}

<div class="col">
    <form action="/compare" enctype="multipart/form-data" method="post">

    <fieldset>

    Enter File 1<br><input type="file" name="file1" id="file1"><br><br>

    Enter File 2<br><input type="file" name="file2" id="file2"><br><br>

    Please select<br><select name="algorithm">
        <option value="lines">lines</option>
        <option value="sentences">sentences</option>
        <option value="substrings">substrings</option>
    </select>
    <br><br>
    Enter a length<br><input type="number" name="length">

    <button type="submit">Compare</button>

    </fieldset>

    </form>
 </div>

{% endblock %}

Here is code for helpers.py

def lines(a, b):
    """Return lines in both a and b"""

    aFileList = []
    bFileList = []
    aList = [] #Create a list to hold each string ending in \n in file a
    bList = [] #Create a list to hold each string ending in \n in file b
    cmpList = [] #This will be the list that stores the strings found in both files a and b
    finalList = [] #I'll scrub the data one more time looking for duplicates


    for string in a.split() : #Build a list with each string separated by a space
        aFileList.append(string.replace('\n', ''))#delete each newline char
    for string in aFileList:
        aList.append(string.replace('.', ''))#delete each period

    for string in b.split() : #Build a list with each string separated by a space
        bFileList.append(string.replace('\n', ''))#strip out newline chars
    for string in bFileList:
        bList.append(string.replace('.', ''))#delete periods from list

    for aString in aList: #Comgbine both lists
        cmpList.append(aString)
    for bString in bList:
        cmpList.append((bString))

    finalList = list(dict.fromkeys(cmpList))#Remove duplicates from cmpList

    return finalList


def sentences(a, b):
    """Return sentences in both a and b"""

    aList = [] #Create a list to hold each string ending in \n in file a
    bList = [] #Create a list to hold each string ending in \n in file b
    cmpList = [] #This will be the list that stores the strings found in both files a and b


    for line in a.split('\n'):
        aList.append(line)

    for line in b.split('\n'):
        bList.append(line)

    cmpList = set(aList) & set(bList)

    return cmpList


def substrings(a, b, n):
    """Return substrings of length n in both a and b"""


    aFileList = []
    aFileList2 =[]
    aFileList3 =[]
    aFileList4 =[]
    aListSplit = []


    for char in a: #Build a list with each char
        aFileList.append(char.replace('\n',''))

    for char2 in aFileList:
        aFileList2.append(char2.replace('.', ''))

    for char3 in aFileList2:
        aFileList3.append(char3.replace(' ', ''))

    aFileList4 = list(filter(None, aFileList3))

    userInput = n
    i = 0
    tmp = ''
    count = 0

    aLen = len(aFileList4)

    while(i < aLen):
        if(i + userInput > aLen):
            break
        else:
            while(count < userInput):
                tmp = tmp + aFileList4[i]
                i = i + 1
                count = count + 1
        aListSplit.append(tmp)
        count = 0
        tmp = ''

    bFileList = []
    bFileList2 = []
    bFileList3 = []
    bFileList4 = []
    bListSplit = []

    for char in b: #Build a list with each char
        bFileList.append(char.replace('\n',''))

    for char2 in bFileList:
        bFileList2.append(char2.replace('.', ''))

    for char3 in bFileList2:
        bFileList3.append(char3.replace(' ', ''))


    bFileList4 = list(filter(None, bFileList3))

    i = 0
    tmp = ''
    count = 0

    bLen = len(bFileList4)

    while(i < bLen):
        if(i + userInput > bLen):
            break
        else:
            while(count < userInput):
                tmp = tmp + bFileList4[i]
                i = i + 1
                count = count + 1
        bListSplit.append(tmp)
        count = 0
        tmp = ''

    finalList = []
    finalList = set(aListSplit).intersection(bListSplit)

    return finalList

1 Answer 1

1

You're browsing templates, not pages generated from templates.

You need to call flask run in your similarities directory, and point your browser to the URL flask will present.

Something like

cd ~/workspace/pset6/similarities
flask run

(path might be different, and server is stopped via Ctrl+C)

Umm... you're using the IDE50, right? Flask might require extra parameters for IP and port otherwise.

1
  • It was an issue of trying to run the page inside of the ide preview screen. As soon as I opened up in a new tab it worked fine. Thank you for taking a look I appreciate it!!
    – ndjustin20
    Commented Mar 29, 2018 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .