Solution 1 :

The error message tells you the problem. Django is trying to access the URL externalApp/ but can’t find that URL when “Using the URLconf defined in FBZ.urls”.

In your HTML form you’ve set the action to be /externalApp/.

In your you have the URL ShopBot/ pointing to you externalApp view.

I would change that last path in your to use the URL externalApp/ .

Other points:

  1. Read up on giving names to URLs. That way you can refer to them in your templates (like in your form’s action) using the url template tag and you won’t have this problem.

  2. It seems very weird to me that you’re calling an external python file. I’d have this code within the Django project itself, but maybe you have a good reason for this structure.

  3. In the view I would use a Django Form, which will make it easier to make the form more robust, and provide validation, which you’re not currently doing.

Good luck!

Problem :

I am trying to have a user input their information in the HTML form and then send it to my Python app that is located in the root of the directory and then run the python program. Below is my code for and my html form.

My program I want to execute is and would take the variables and use them in the program.

How do I pass a variable from the HTML to my Python app and then execute the program? I followed along with a youtube video to setup the externapApp function but I’m having problems executing and making sure the variables are passed to the app.


<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

        <div class="jumbotron jumbotron-fluid">
            <div class="container">
              <h1 class="display-4">Flatbush Zombies Shop Bot</h1>
              <p class="lead">This is a bot written in Python that will shop <a href="">this</a> website for you. This website sells out of its products right away when they are released so this bot can purchase your desired items in an instant!</p>
        <div class="form">
            <form action="/externalApp/" method="POST">
                {% csrf_token %}
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">First name</span>
                    <input id="first_name" type="text" name="user_first_name" value="{{ user_first_name }}">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">Last name</span>
                    <input id="last_name" type="text" name="user_last_name" value="{{ user_last_name }}">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">Email</span>
                    <input id="email" type="text" name="user_email" value="{{ user_email }}">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">Phone</span>
                    <input id="phone" type="text" name="user_phone" value="{{ user_phone }}">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">Address</span>
                    <input id="address" type="text" name="user_address" value="{{ user_address }}">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">City</span>
                    <input id="city" type="text" name="user_city" value="{{ user_city }}">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">Zipcode</span>
                    <input id="zipcode" type="text" name="user_zipcode" value="{{ user_zipcode }}">
                <button type="submit">Submit</button>


    from django.shortcuts import render
from django.http import HttpResponse
import requests
from subprocess import run,PIPE
import sys

def shopbotView(request):
    context = {}
    return render(request, "index.html", context)

def externalApp(request):
    user_first_name = request.POST.get('user_first_name')
    user_last_name = request.POST.get('user_last_name')
    user_email = request.POST.get('user_email')
    user_phone = request.POST.get('user_phone')
    user_address = request.POST.get('user_address')        
    user_zipcode = request.POST.get('user_zipcode')
    user_city = request.POST.get('user_city')

    output= run([sys.executable, '//Users//will/Documents//GitHub//FBZbot//env//FBZ//ShopBot//',user_first_name,user_last_name,user_email,user_phone,user_address,user_zipcode,user_city],shell=False,stdout=PIPE)

    return render(request, 'index.html',{'data1':output}) (file I want to populate from HTML form, then execute)

import time
from selenium import webdriver
from import externalApp

# Init broswer
driver = webdriver.Chrome("/Users/will/Documents/GitHub/FBZbot/chromedriver")

# Find product and select size
item = driver.find_element_by_xpath('//*[@id="ProductImage-14397485580370"]')

# Add item to cart
add_to_cart = driver.find_element_by_xpath('//*[@id="product_form_4512114081874"]/div[5]/button')

# Checkout with cart
checkout = driver.find_element_by_xpath('//*[@id="PageContainer"]/main/section/form/div/div/input[2]')

# Enter checkout information
email = driver.find_element_by_xpath('//*[@id="checkout_email"]')
first_name = driver.find_element_by_xpath('//*[@id="checkout_shipping_address_first_name"]')
last_name = driver.find_element_by_xpath('//*[@id="checkout_shipping_address_last_name"]')
address = driver.find_element_by_xpath('//*[@id="checkout_shipping_address_address1"]')
city = driver.find_element_by_xpath('//*[@id="checkout_shipping_address_city"]')
zipcode = driver.find_element_by_xpath('//*[@id="checkout_shipping_address_zip"]')
phone = driver.find_element_by_xpath('//*[@id="checkout_shipping_address_phone"]')

# Fill out checkout data

from django.contrib import admin
from django.urls import path
from ShopBot.views import shopbotView
from ShopBot.views import externalApp

urlpatterns = [
    path('ShopBot/', shopbotView),
    path('ShopBot/', externalApp)

The error I get is: Using the URLconf defined in FBZ.urls, Django tried these URL patterns, in this order:

The current path, externalApp/, didn’t match any of these.