Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7051091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:13:21+00:00 2026-05-28T03:13:21+00:00

I want to update url pattern match with my product when I change database,

  • 0

I want to update url pattern match with my product when I change database, so I using in urls.py:

main_cagetory_url=Product_category.objects.get_all_product_category_url()
main_cagetory_url_string = '(?:' + '|'.join(main_cagetory_url) + ')'

product_url=Product.objects.get_all_product_url()
product_url_string = '(?:' + '|'.join(product_url) + ')'

menu_url=Menu.objects.get_all_menu_url()
menu_url_string = '(?:' + '|'.join(menu_url) + ')'

urlpatterns = patterns('',
                       (r'^$',menu_page),
                       (r'^home_vi$',home_vi),
                       (r'^home_en$',home_en),
                       (r'^'+menu_url_string+'$',menu_page),
                       (r'^'+main_cagetory_url_string+'$',list_product),
                       (r'^'+product_url_string+'$',product_detail),
                       (r'^search_result$',search_result),
                       (r'^admin/', include(admin.site.urls)),)

Every thing ok when I’m developing in my pc. But when I uploadd my project to host. Every time I add new Product_category or Product. Django cannot realize that change and show 404 error when I click to new Product_category or new Product.

How can I fix that bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:13:21+00:00Added an answer on May 28, 2026 at 3:13 am

    This started as a comment, but I thought I would try avoid creating a serial comment.

    The reason this works in development mode is because the dev server automatically reloads any files (e.g. urls.py) that change. This doesn’t happen (and you don’t want it to happen) on a production server. I’ve never had a need to do this myself so I’m taking a hard look at the code & docs to see where the hooks may be.

    Well after spending about 45 minutes on this my answer seems to be … you can’t do this, at least not easily. Note all line numbers below are from Django 1.3.1.

    Django initializes your urls from the module named in your settings file as ROOT_URLCONF, normally urls. This initialization is somewhat expensive and Django goes out of its way to cache everything it can.

    In BaseHandler.get_response() (django/core/handles/base.py line 83) urlresolvers.set_urlconf() is called using the urls modules named in settings.ROOT_URLCONF. Effectively, this is global, hardwired knowledge about where the url configuration lives. Because of caching it only initializes your urls once per thread. That means that each thread in the web server that is handling your Django requests would need to be alerted to flush-and-initialize its urls every time there’s a database change, and that gets complicated all by itself.

    An alternative method would be to either create a super pattern that calls a view, which in turn makes a DB call. Another approach is to handle this in a middleware class where you test for a 404 error, check if the pattern is likely to be one of your categories, and then do the DB look up there. I have done this in the past and it’s not as bad as it sounds. Look at the django/contrib/flatpages code for a straightforward implementation of this approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to update my sqlite database but i cannot find the way to
Like iPhone safari browser, I want to update UItextview with current url of UIWebView
I want update a column by adding days to current time. In pseudosyntax it
I want to update a list of storage devices as the user inserts USB
I want Windows Update to automatically download and install updates on my Vista machine,
I want to update two columns in a table. The value of the second
I want to update/upgrade the standard Leopard install of Sqlite3 to >3.5 to use
I want to update some file in a server, with an automated script and
I want to update a column in a table making a join on other
I want to update a .class file in a jar with a new one.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.