Django Internationalization Tutorial-1
Tags: djangointernationalization, webtranslation, python, django
Published: 2022-02-09 17:04:18

---
###              `Introduction and Base Project` .

Before starting here if you are familiar with creating Django project feel free to skip this tutorial and start the next.  

If not just make sure you have installed python and Django in your system by follow command, if you want more detail follow [Django Website ](https://www.djangoproject.com/download/) 

``` python 
pip install django
```
above command will install Django application in system, now we need to create project directory where we can store our code and manage to run, copy below code, and run in your CMD/Terminal 

``` python
django-admin startproject langtests
```

This will create the langtests directory in the current working directory. To create the languages app, cd into langtests and execute: 

``` python 
python3 manage.py startapp languages 
```

The directory structure of our project will be the following: 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99sr2l59pggtw9iixmqe.png)

Here, langtests contains 1 manage.py file, one sub directory which contains 4 python files with extension .py file such as settings.py, urls.py, wsgi.py and \__init__.py. and last i.e.  third one is 2nd sub folder which is our application i.e., languages, this contains 5 python files and one folder with name migrations, migrations folder store all db file info will discuss this in other post, now look at 5 diff files namely \__init__.py, admin.py, models.py, tests.py, and views.py,  
 
Overview of each file: 

\__init__.py:  An empty file that tells Python that this directory should be considered a Python package. 

settings.py: Contains all the information of projects such as Database, Template, Middleware, Third Party, i18N, Static information and many more. Settings/configuration for this Django project. [Django settings](https://docs.djangoproject.com/en/2.2/topics/settings/) will tell you all about how settings work. 

urls.py: The URL (Uniform Resource Locator) declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs (Uniform Resource Locators) in [URL dispatcher](https://docs.djangoproject.com/en/2.2/topics/http/urls/). 

wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details. 
If you have worked with Django, you already know what these files are. If not, I recommend following the [Django tutorial](https://docs.djangoproject.com/en/2.2/intro/tutorial01/) as it will allow you to understand most of the basic concepts. 

Let get touch some code introductory code part:  

Let create a simple view for our 'languages' app's index page. Open languages/views.py and paste the code below: 

```python 
from django.http import HttpResponse

def index(request):
     output = 'Welcome to my site.'
     return HttpResponse(output)
```
This view will now be mapped to a URL. Created a file named urls.py in the languages directory that contains the following code: 

```python
from django.contrib import admin
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
]
```

Finally, from the root URLconf, map a URL. Include the URLs for the language apps in urlpatterns in langtests/urls.py as follows: 

```python
from django.conf.urls import include
from django.contrib import admin
from django.urls import path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('languages/', include('languages.urls')),
]

```
To test the view, start the Django server using below command 

```python
python3 manage.py runserver
```

and navigate to [http://localhost:8000/languages/](http://localhost:8000/languages/)  in your browser. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hvzuo8amsua6lm0si0lt.png)

Disclaimer: This is a personal [blog, post, statement, opinion]. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally.