This Django app demonstrates a simple "Hello World" application with two routes. One route returns a JSON message, and the other renders an HTML page.
- Python 3.8 or higher
- Django 3.2 or higher
-
Clone the Repository
If you have this project in a GitHub repository, provide the command to clone it. If not, the user needs to download the project files to their local machine.
git clone https://github.com/SyedAbbuTurab/HelloWorldAppDjango cd myproject
-
Create a Virtual Environment (Optional but Recommended)
On Windows:
python -m venv venv .\venv\Scripts\activate
On macOS and Linux:
python3 -m venv venv source venv/bin/activate
-
Install Dependencies
Install Django using pip. Ensure you are in the project directory where
requirements.txt
is located (if you have one).pip install django
-
Migrate the Database
Set up the initial database tables.
python manage.py migrate
-
Run the Development Server
Start the Django development server.
python manage.py runserver
Once the server is running, you can access the routes in a web browser or using a tool like curl
.
-
JSON Response Route
To get the JSON response, visit
http://localhost:8000/helloworld/hello/
. This will return a JSON object with the message "Hello World!".{"Message": "Hello World!"}
-
HTML Page Route
To view the HTML page, navigate to
http://localhost:8000/helloworld/hellohtml/
. This route renders an HTML page displaying "Hello World!" in bold.
Briefly describe the key directories and files in your project, for example:
helloworld/
: The Django app containing the views and templates.templates/
: Contains the HTML templates for the app.views.py
: Defines the views for the JSON response and the HTML page.
myproject/
: The Django project directory.settings.py
: Project settings including theINSTALLED_APPS
configuration.
manage.py
: A command-line utility that lets you interact with this Django project.
-
Creating an Admin User
If your app uses Django's admin, include instructions for creating an admin user.
python manage.py createsuperuser
-
Running Tests
Provide instructions for running tests if your app includes them.
python manage.py test
Include licensing information here.