Coder Social home page Coder Social logo

first-django-app's Introduction

first-django-app

Simple "Hello World" app for learning Django URL Mapping. Utilized direct mapping as well as indirect mapping via the include() function.

Direct Mapping

This provides direct access to a view through its URL. It links the views.py file from the app straight to the urls.py file in the project.

Direct Mapping Syntax

---In views.py file (app)---

from django.shortcuts import render

from django.http import HttpResponse

def index(request): return HttpResponse("Hello World!")

---In urls.py file (project)---

from django.contrib import admin

from django.conf.urls import url

from django.urls import path

from django.conf.urls import include

from AppTwo import views

urlpatterns = [

url('', views.index, name='index'),

url(r'^AppTwo/', include('AppTwo.urls')),

path('admin/', admin.site.urls),

]

Include() Function

This allowewd me to look for a match with regex and link to an app's urls.py file.

Include() Syntax

from django.conf.urls import include

urlpatterns = [

    url(r'^app_name/', include('app_name.urls')),

]

The above code allows us to look for any match and find its urls.py file in the matching app. This is useful because instead of adding every app url to our project's urls.py file, we can make each app's urls.py file searchable independantly based off its unique regex pattern.

first-django-app's People

Contributors

daymond-blair avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.