0

After going through Django Project's tutorial on creating a polling app, named polls, I started my own project on the same virtual environment, under another name. Now, what I did in my new app under the the index view, is still being only shown at http://127.0.0.1:8000/polls/ where it should be at http://127.0.0.1:8000/mynewproject/

I need help on correcting this, or is it a fact that on one virtual environment, I can work on one django project? And as a second question, should I be setting each project up on different virtual envs?

OddvarK
  • 1
  • 2

1 Answers1

0

First Answer:

First I wan to mention these two things

  1. It doesn't matters how many projects are there in your virtual environment each can be handled by different different manage.py.
  2. And each project runs on different addresses if you do but single app won't run on different addresses (until you do it manually).

As you mentioned here you had created another app inside same project like this

Project
-- manage.py
-- Project
-- -- settings.py
-- -- urls.py <<--- Main url pattern file for whole project
-- -- wsgi.py
-- App1
-- -- views.py
-- -- models.py
-- -- urls.py <<-- Another specific urls pattern file for App1 (optional)
-- -- others
-- App2
-- -- views.py
-- -- models.py
-- -- urls.py <<-- Another specific urls pattern file for App2 (optional)
-- -- others

So if you register urlpatterns for every particular apps like

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^home/$',views.home, name = "app_home"),
]

and

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^home/$',views.home, name = "app_home"),
]

then you have to include both of these urls.py files in projects main urls.py like this

from django.conf.urls import url, include

urlpatterns = [
    url(r'^app1/', include('app1.urls')),
    url(r'^app2/', include('app2.urls')),
]

or if you don't wanna go like this you can register both url patterns in main urls.py

from django.conf.urls import url, include from django.contrib import admin

urlpatterns = [
    url(r'^app1/home', App1.views.home),
    url(r'^app2/home', App2.views.home),
]

So, that is it, you just have to deal with urls.py files.

Second Answer: You can create multiple projects in single Virtual Environment. But configurations like packages and their versions stays same for all. If you make changes there (by upgrading, degrading, installing or uninstalling) then it will affect all projects inside that Virtual Env.

aquaman
  • 451
  • 5
  • 16