# 404 error when deploying django project with apache2

**URL:** <https://forum.djangoproject.com/t/404-error-when-deploying-django-project-with-apache2/1961>\
**Category:** Using Django\
**Created:** [April 14, 2020, 7:13pm UTC](https://forum.djangoproject.com/t/404-error-when-deploying-django-project-with-apache2/1961 "2020-04-14T19:13:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nemuo](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@nemuo](https://forum.djangoproject.com/u/nemuo)\
**Post date:** [April 14, 2020, 7:13pm UTC](https://forum.djangoproject.com/t/404-error-when-deploying-django-project-with-apache2/1961/1 "2020-04-14T19:13:56Z")

</div>

Please let me ask a naive question since I cannot find any systemized documents on django for beginners on the internet.  
Since I got an error that I cannot put more than 2 links, I replace “/” with “|” in my post.

I tried to create a new django project on apache2, but I got 404 error. Here are what I did.

In |home|ubuntu|django directory, type

> django-admin startproject proj

Edit proj|proj|wsgi.py as follows.

> import os  
> import sys
> 
> from django.core.wsgi import get\_wsgi\_application
> 
> os.environ.setdefault(‘DJANGO\_SETTINGS\_MODULE’, ‘proj.settings’)
> 
> sys.path.append(‘|home|ubuntu|django|proj’);  
> sys.path.append(‘|home|ubuntu|django|proj|proj’);
> 
> application = get\_wsgi\_application()

Edit ALLOWED\_HOSTS in proj|proj|settings.py as follows.

> ALLOWED\_HOSTS = [‘[example.com](http://example.com)’]

Edit |etc|apache2|conf-available|wsgi.conf as follows.

> WSGIScriptAlias |proj |home|ubuntu|django|proj|proj|wsgi.py  
> WSGIPythonPath |home|ubuntu|django|proj
> 
> \<Directory |home|ubuntu\>  
> Require all granted  
> \<|Directory\>
> 
> \<Directory |home|ubuntu|django|proj|proj\>  
>   
> Require all granted  
> \<|Files\>  
> \<|Directory\>

I don’t touch urls.py. It is just a default version as follows.

> from django.contrib import admin  
> from django.urls import path
> 
> urlpatterns = [  
> path(‘admin|’, admin.site.urls),  
> ]

Restart apache2 as

> |etc|init.d|apache2 restart

Access to http:||example.com|proj, and then got 404 error as follows.

> Page not found (404)  
> Request Method: GET  
> Request URL: http:||example.com|proj|  
> Using the URLconf defined in proj.urls, Django tried these URL patterns, in this order:
> 
> admin|  
> The empty path didn’t match any of these.

My enviroment is as follows.

> Ubuntu 18.04 LTS (AWS)  
> Apache|2.4.29  
> Python 3.6.9  
> Django 3.0.5

How can I solve this 404 error?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 14, 2020, 7:23pm UTC](https://forum.djangoproject.com/t/404-error-when-deploying-django-project-with-apache2/1961/2 "2020-04-14T19:23:10Z")

</div>

The good news is that it appears like your Django setup is effectively working. You’re getting a Django error, which means that apache is handing the request off to Django. This means that the problem is in the Django side, not the apache side.

The issue is the URL you’re trying to reference. Proj is actually not part of your url scheme. Notice in your urlpatterns, you’re only defining admin, you have no reference to a url component named ‘proj’. (Nor should you, unless you have created a view to be called for that url.)

Verify your project is working by going to /admin. All your other urls that you want need to be created as Django views and then registered in the urlpatterns.

There’s a separation between your directory structure of your project and the url structure of your application. There doesn’t need to be any correlation between the two.

If you haven’t already done so, I strongly encourage you to work through the full [Django tutorial](https://docs.djangoproject.com/en/3.0/intro/tutorial01/). It’s a whole lot easier to deploy a fully working Django app than it is to try to do development in the deployed environment.

Ken
