Skip to content

Akp-arvind/Django-FSD-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django-FSD-lab

INDEX

  1. Cloning the Repository
  2. Installation
  3. Project Creation
  4. Running the Program
  5. App Creation
  6. Setting Up the Local System Environment

Cloning the Repository

To clone the repository, use:

git clone https://github.com/Akp-arvind/Django-FSD-lab

Installation

  • Libraries: You can install the required libraries using pip. Open your terminal or command prompt and run the following command:
pip install -r requirements.txt
  • Download and install the XAMPP server
https://www.apachefriends.org/download.html

OR

  • Download and install WAMP server
https://sourceforge.net/projects/wampserver/files/latest/download
  • For WAMP, many files will be missing and the system asks to install them. Hence download the files from this website:
https://wampserver.aviatechno.net/

(Last link ; chose second file after getting redirected ; Windows_64_bit)

Project creation

Open the terminal and enter the following command:

django-admin startproject <project_name>

( e.g. - "lab" )

Observe that some files are generated.

Running the Program

Once you have installed the necessary libraries, and satisfied the program specific requirements, you can run the program by following these steps:

  1. Navigate to the project directory using the terminal or command prompt.
  • Ensure that XAMPP/WAMP server is running (if required).
  1. Run the following command to start the Django server:
python manage.py runserver
  1. Open your web browser and enter the following URL:
http://localhost:8000

OR

http://127.0.0.1:8000

You should now be able to access the program.
You would have to enter the path manually this way.

App creation

To create an app, enter the following command in the terminal:

python manage.py startapp <app_name>

( e.g. - "ap2" )

In settings.py file, under TEMPLATES, set:

'DIRS':[os.path.join(BASE_DIR,'ap2/templates')],

This will ensure that the templates for the "ap2" app are accessible.

  1. Current date and time (ap1)

http://localhost:8000/cdt/
  1. Time delta (ap1)

http://localhost:8000/fhb/
http://localhost:8000/fha/
  1. Templates (ap2)

http://localhost:8000/showlist/
  1. Template Inheritance (ap3)

  • In settings.py, change the DIRS to ap3/templates, run the code and go to:
http://localhost:8000/home/
  • Navigation can be done via clicking the links
  • Observe the changes in URL after clicking
  1. Models (ap4)

  • In settings.py switch "ap3/templates" with "ap4/templates" under DIRS
  • After successful installation of the server from Installation segment, start it and go to:
http://localhost/phpmyadmin
  • Create a new database - “studentreg” (db name)

  • In settings.py file:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ap4', # added
]
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        # changed from sqlite3 default
        'NAME': 'studentreg', 
        # changed for ap4
        'USER': 'root', 
        'PASSWORD': '', 
        'HOST':'localhost', 
        'PORT':'3306',
    }
}
STATIC_URL = 'static/'
STATICFILES_DIRS=[os.path.join(BASE_DIR, 'ap4/static')] 
# added
python manage.py makemigrations ap4
python manage.py migrate
  • Add entities in the database tables (ap4_student and ap4_course)
  • NOTE: migrations should be done every time models.py changes or any database table changes.

Finally, for viewing the output, run the code and open your web browser to enter the followinbg URL:

http://localhost:8000/reg/
  • Remember to stop the server once you're done.
http://localhost:8000/course_search/
  1. Admin Interface (ap4)

  • Changes made to the code have been indicated in the comments.

  • Set the username and password by entering the following command in the terminal:

python manage.py createsuperuser
  • Make changes to the db using the admin UI.

To login, enter the following URL in your web browser:

http://localhost:8000/admin/
  1. Model Form (ap4)

  • Perform migrations if required, run the app and go to:
http://localhost:8000/add_project/
  • Add the indicated fields.
  • The changes can be viewed here (ap4_project):
http://localhost/phpmyadmin
  1. Generic Views (ap4)

  • Use the following paths for getting generic and detailed views (pre-registered students):
http://localhost:8000/student_list/
http://localhost:8000/student_detail/
  • /<int: pk>/ (primary key, e.g. - "/2/") can be apppended here which will display the details of the corresponding student.
  1. CSV and PDF gen (ap4)

  • Ensure that the data has been inserted beforehand.
  • 9 A
http://localhost:8000/construct_csv_from_model/
  • 9 B
http://localhost:8000/construct_pdf_from_model/
  • Observe that the files get downloaded as soon as the path is entered.
  1. Registration using AJAX (ap4)

  • Ensure that "jquery.min.js" file is present in the static folder.
http://localhost:8000/regaj/
  • Observe that the output is displayed on the same web page (reloading is not required, thanks to Ajax).
  1. Search using AJAX (ap4)

http://localhost:8000/course_search_ajax/
  • Again, the partial output is loaded on the same page.



Setting Up the Local System Environment

  1. Create a new folder for your project.
  2. Open the command prompt and navigate to the newly created folder.
  3. Enter the following command to create a virtual environment named "env":
python -m venv env

This will create a new virtual environment in the "env" folder.

  1. Activate the virtual environment by running the following command:
env\Scripts\activate
  1. You can now install the necessary libraries and run the program as mentioned in the previous instructions.

If you're using VS Code, go to View - Command Palette - Python: Select Interpreter - 3.11.1 ( 'env':venv )

Remember to deactivate the virtual environment when you're done by running the following command:

deactivate

This will ensure that your system environment is properly set up for the project.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published