Creating a New Django Project

Before getting started, make sure you have Python and pip installed on your system. If you don’t already have them, you can download them from the official Python website and official Pip website.

With Python and pip installed, you can create a new Django project. First, install Django using pip:

pip install django

Then, create a new Python file (e.g., app.py) and add the following code to create a basic Django application:

app.py
from django.conf import settings
from django.http import HttpResponse
from django.urls import path
from django.core.wsgi import get_wsgi_application

# Basic Django settings
settings.configure(
    DEBUG=False,  # Turn off debug mode
    SECRET_KEY='mysecretkey',  # Set your secret key
    ALLOWED_HOSTS=['*'],  # Allow all hosts for simplicity
    ROOT_URLCONF=__name__,  # Set the root URL configuration to this module
    MIDDLEWARE_CLASSES=(),  # Use an empty tuple to disable middleware
)

# Simple view
def index(request):
    return HttpResponse("Hello world!")  # Return a simple HTTP response

# URL configuration
urlpatterns = [
    path('', index),  # Map the root URL to the index view
]

# WSGI application
application = get_wsgi_application()

# WSGI server
if __name__ == "__main__":
    from wsgiref.simple_server import make_server
    httpd = make_server('', 80, application)  # Serve the application using the WSGI server on port 80
    print("Django server running on port 80...")
    httpd.serve_forever()  # Start the server

In the above code, we create a basic route that returns “Hello, World!” when accessed. The application is configured to run on port 80, which is the default port for HTTP traffic.

Managing Dependencies with the requirements.txt file

The requirements.txt file is a file that lists all external libraries required for your project. You should list all libraries your project will use, excluding native libraries like random and datetime. This file should be included when submitting your application to Square Cloud.

requirements.txt
django

Creating the squarecloud config file

Learn about: how to make the configuration file for Square Cloud.

The squarecloud.app file is a configuration file that will be used to configure your application; it will be used to define the name, description, version, main file, among other things.

Configuring the START Field

In the Square Cloud configuration file, the START field is optional and is only necessary if you are using a custom script to start the website. In the example provided, the START field is not necessary.

Purchasing a Plan Before Uploading Your Project

Before you can upload your project to Square Cloud, it’s important to understand that you need to purchase a plan. The type of plan you choose will depend on the resources required by your application. You can view our plans here.

Are you wondering how much RAM and CPU your plan needs to host a Django application? Don’t worry, we’re here to help. Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It’s built by experienced developers and takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. Our Standard plan offers 4GB of RAM and 1vCPU, which should be sufficient for most Django applications. However, if you’re working on a larger project and seeking extra stability, we recommend considering our Pro plan. With additional resources, you can maintain stability even during peak demand. To purchase, simply click here.

Uploading your project to Square Cloud

After following all the steps, package your application files into a zip file where the configuration file is, and upload the application on Upload. Remember to include the requirements.txt file, but do not include files like __pycache__. You can get more information about unnecessary files when hosting at automatic-deletion-files-when-deploying-an-application-to-squarecloud.

Troubleshooting

Additional Resources

For more information about Django and its tools, visit the official Django documentation. There, you’ll find detailed guides, tutorials, and API documentation to help you make the most out of Django.

If you continue to experience any issues, please don’t hesitate to contact our support team.